开发者

How can I open a new application (Facebook) from inside an app I made in iOS

开发者 https://www.devze.com 2023-02-03 23:04 出处:网络
How can开发者_运维技巧 I open the facebook application from a app I made recently?You need support from the application you wish to open.If an application is configured to handle a custom URL scheme,

How can开发者_运维技巧 I open the facebook application from a app I made recently?


You need support from the application you wish to open. If an application is configured to handle a custom URL scheme, you can use UIApplication's openURL method to open it.

Luckily for you, the Facebook application does support a custom URL scheme. Details here. Note that this isn't a documented interface, so the Facebook app could take this functionality away in an update. To handle this correctly, plus to handle the case where the user doesn't have the app installed, you should check using UIApplication's handleURL method.

Depending on what you are doing, using Facebook's API might be a better approach for you to take.


You open other applications if they have an URL scheme, an apps URL scheme may change with any update or even be removed completely, so always check to see if the app is installed/the URL scheme hasn't be changed or removed.

UIApplication is used to do these 2 things.

You need to first get the sharedApplication

[UIApplication sharedApplication]

Then use canOpenURL:(NSURL *)url to see if the app can be opened. This won't check if the URL is valid for that app, so it might still fail if this returns YES. But the other app will definately open if YES is returned.

And then use openURL:(NSURL *)url to actually open it.

eg:

//myURL is already set up
if ([[UIApplication sharedApplication] canOpenURL:myURL]) {
    if (![[UIApplication sharedApplication] openURL:myURL]) {
        //There was an error opening the URL
    }
}

http://handleopenurl.com/ Is the place to look up URL schemes for apps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号