How to determine if Dropbox has been installed on iOS device?

心已入冬 提交于 2019-12-12 09:19:05

问题


My app uses Dropbox to allow users to make backups of their core data store. Is there a way to determine programmatically if the Dropbox app has been installed, so I can prompt users to set up the backup? I don't want to bug users who don't use Dropbox, but I want to try to get as many users to use backups as possible.


回答1:


Dropbox define their own URI scheme, dbapi-1, and as such you can see if the OS can open URLs using that scheme, as so:

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"dbapi-1://"]]) {
    NSLog(@"Dropbox is installed.");
} else {
    NSLog(@"Dropbox is not installed.");
}



回答2:


The currently accepted answer is not appropriate. dbapi-1 may not always work. It really depends on if you're using the SDK or not (which you should).

If you read the code for DBChooser.m (https://github.com/dropbox/dropbox-ios-dropins-sdk/blob/master/DBChooser/DBChooser.m) you will see the following method:

+ (NSURL*)dbc_chooserURLForAppKey:(NSString*)appKey linkType:(DBChooserLinkType)linkType
{
    NSString *baseURL = [NSString stringWithFormat:@"%@://%@/chooser", kDBCProtocol, kDBCAPIVersion];
    NSString *linkTypeString = [[self class] dbc_getLinkTypeString:linkType];

    return [NSURL URLWithString:[NSString stringWithFormat:@"%@?k=%@&linkType=%@", baseURL, appKey, linkTypeString]];
}

The constant kDBCProtocol is what you need. Currently the latest is dbapi-3. You should always use the one that is corresponding with the framework you are using, if you are using the newest Dropbox sdk.



来源:https://stackoverflow.com/questions/15095845/how-to-determine-if-dropbox-has-been-installed-on-ios-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!