简体   繁体   中英

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

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.

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.");
}

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.

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