How add new window on button click and come back to previous window? - iphone

I have an application in which i have a button. I want to open a fb login url in browser and when i login successfully then i want to come back to my application. So problem is that how i fix that?
i use this code for.
-(IBAction)add_account:(id)sender{
switch ( ((UIButton*)sender).tag ){
case 0:
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://graph.facebook.com/oauth/authorize?client_id=xxxxxxxxxxxxx&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=touch&scope=offline_access,publish_stream,read_stream"]];
break;
}
}
}
Thanks in advances...

You need to register an URL scheme for your own app. You can put the URL scheme in your app's project file on the "Info" tab, lower right is an "Add" button which allows to add an URL type. You can now edit that URL type in the list, especially filling out the identifier and more important the URL scheme. Assuming your URL scheme is "myapp":
Every URL starting with myapp:// now will be forwarded to your app. Now you simply have to implement application:openURL:sourceApplication:annotation in your application delegate which will handle all "myapp://" URLs. There you can, for example, extract information from the URL and show a specific view.
The myapp://-URL would of course go as redirect target in your original request.

Related

iPhone SDK - Add a "Add to Home Screen" button in a UIWebView

I have a native iPhone app, which has a UIWebView component to it. I am trying to see if I can replicate the "Add to Home Screen" button that is present in the tab bar options in Safari.
Is this possible inside a UIWebView within a native app?
Thanks!
Brett
[I presume your question is about replicating the action associated with add to home screen, rather than replicating the appearance of the button itself (which being pedantic is what you actually wrote).]
As others have said this isn't possible.
What you could do is programatically launch Safari from within your app and give it the URL of a page to load which is your page.
When your page is loaded it has some sort of animation and shows the user where the add to home screen button is and tell them to press it after clicking a link which is displayed in your web page. When the users click on the link it takes them to whatever page it is that you would like saved to the desktop, and you hope they follow your instructions.
If you register your app to handle a proprietary url scheme the users can get back to your app from within Safari by clicking on a link using your app's url scheme.
The web pages that you seed Safari with must however be remote pages, you cannot give Safari a page in your app's bundle or that your app has downloaded as Safari cannot read pages from your app's sandbox.
The short answer is no, you can't. Apple does not let you.
Here's a similar question which may help you come up with other possibilities:
Javascript for "Add to Home Screen" on iPhone?
If I had to think of a work around off the top of my head, you could create an javascript pop-up which instructs them how to. It could say something like tap this button to go to mobile safari then tap action -> add to home screen.
Execute the Javascript with UIWebView's method:
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
Hope this helps.
You can use UIActivityViewController with your url as the activity items
NSArray *activityItems = #[title, url];
And then you can exclude the activities that you don't want. I think it´s the only way for now.

How to register a custom app opening URL scheme with Xcode 4?

Xcode4 is asking for a huge number of arguments just to make this simple thing possible:
NSString *stringURL = #"twitterriffic://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
What are all these properties for? Why an image? Must I repeat the app identifier here? What role to choose if I want anyone to be able to call this URL to open my app? And what are these Additional url type properties for?
I found no Xcode4-related tutorial how to register such an URL scheme with Xcode 4.
Open "Supporting Files" (folder) on left and click the "YourAppName-Info.plist"
Choose a row like "Bundle creator OS Type Code" and mouse over row and click the (+) symbol
This creates a new row and type "URL types"
Click the arror to left and see Item 0 and you'll rename the value in Item 0 to "URL Schemes" as shown
Then edit the field in Item 0 and type in your prototocol; I typed in "goomzee" as shown
Now if I install this app on my simulator, and open Safari and type "goomzee://" in the address bar it will launch my app.
Yup, this stuff isn't straightforward is it ?
I've outlined the steps required to register a custom URL here:
Custom URLs
But, basically the key to it is setting up a "URL Types" value in your .plist file. Here's what it looks like in XCode 5:
In this example, I've registered the MKB prefix, so now, I can use this new type of URLs in hyperlinks on webpages, and emails (if I read an email in the iPad Mail app):
If a user taps on one of these links, my iPad app will start up, and I can access the full URL string, to extract the other parameters from the URL (eg "DocumentNumber=100")
The only gotcha is that I have yet to work out how to test whether a user has an iPad app installed which can recognise a particular prefix.
If they haven't, and they tap on one of these MKB:// links on their iPad, they'll get an ugly error message:
You can continue to register your custom URL by editing your app's info.plist file (as shown in one of your previous questions). The new editor in Xcode 4 is supposed to be a convenience to make it easier to add the entries - all it is doing is making the same info.plist changes that you would do manually. If you want to use the new editor then you only need to fill in the 'Identifier' and the 'URL Schemes' boxes. You don't need an image, icon or additional URL properties.
The other properties (icon etc) are not well documented but seem to be applicable only on Mac OS X and might be used in the Finder's Get Info dialog to display what types of URL a particular app can open. For example, take a look at the Launch Services Programming Guide.
What you change in that editor is also reflected in your project's info plist file. It takes the form of ProjectName-Info.plist. Hopefully that helps.

how to move moretab in iphone

in my applicaton,i have one directions tab in moretab.In directions tab, i displays the safari view through coding like this
NSString* url = #"http://maps.google.com/maps?saddr=33.68325,-117.834073&daddr=33.67425,-117.835073&dirflg=w";//[NSString stringWithFormat: #"http://maps.google.com/maps?q=%#",#"1101+E+Fletcher+Ave+Tampa+FL+33612"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
when click the directions tab it shows the safari browser.But my problem is after open the safari view, iam not able to move the more tab again. now what i want be done is ,when closing this safari view and reopen my application it directly shows the more tab not directions tab.How to do this.
Often times directing the user to Safari can be very confusing and some users don't understand how to come back. Consider using UIWebView instead for this since it stays inside your app and also provides you with the control that you are talking about now.
If you absolutely have to direct the user to safari I would take a look at this post that talk about how to catch the events of a user leaving your app and different states for that.

how to place url string

hi i am new to iphone. what i need is i have to place a url as a string eg:http://stackoverflow.com by selecting the string it self open in a web brosewr how can i done this. post some code or link thank u.
Add a textView control onto your NIB file. Put whatever content (you mention 5 lines of text) you want in here. In the properties for this control, under the "Detection" section, click "Links". Then, any URL links in this text will be automatically highlighted in blue, and when your users tap on it they will be taken to that URL in the browser.
Your question could have been a little clearer - I only got what you were after because of your previous comment on puckipedia's answer...
To open A url use (in Objective-C)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLHere]];

Launch Safari from iPhone App

I know that i can use the following code to launch my own url, but i want the user to continue their workflow after using my bookmarklet so therefore don't want to open a new tab and have them re-load the url i put into the url variable?
NSURL url* = [NSURL URLWithString:#"http://google.com"];
[[UIApplication sharedApplication] openUrl:""];
Can this be done?
There is no way to open Safari without actually quitting your app and opening Safari. Or to somehow automatically return the user to your app from Safari once the URL you opened loads.
Or am I misunderstanding the question?
Actually, you can delegate a URL handler to your app. A smart example is shown here:
http://www.mobileorchard.com/lite-to-paid-iphone-application-data-migrations-with-custom-url-handlers/
The scenario is:
- register URL handler
- open Safari as normal
- get Safari to use your custom URL handler that should open your app (eg: myapp://)
Have a look at the way Flickr iPhone app does the authentication.
Can you use 'about:blank' as the url? That should just open Safari with a blank page. I assume this would be similar to tapping the 'number' button in the bottom right then selecting 'new page'.