简体   繁体   中英

Is there a way to get the URL scheme from the bundle identifier in iOS?

I am implementing a document based application. When other applications like dropbox launch my application to open the file, I get from this method the bundle identifier of the application that launched me (dropbox).

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

Now, I would like to put a button that says "Return to dropbox" and launch dropbox app. However, I would need to know the URL scheme to be able to open it this way.

[[UIApplication sharedApplication] openURL:myURL];

Is there a way to obtain the URL scheme of an app from the bundle identifier?

I see that in the Info.plist when setting the URL scheme for my app that the bundle identifier is specified as well. So I figure there should be a way to get one value from the other.

thanks,

No. There is no convention when setting the URL schemes that says they have to be related at all to the bundle identifier. If you are looking for a specific one, or want to try and guess patterns on existing schemes, try here

From iOS9, I think you don't need that feature, because the iOS itself provide a button like that in the top left of your app. But if you want, you can use the sourceApplication from the following delegate method.

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

Here the sourceApplication is the bundle ID of the app that is requesting your app to open the URL (url).

You can check if the bundle identifier belongs to Dropbox and open the Dropbox app eventually using one of Dropbox's URL schemes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM