iOS設備中, APP之間的相互跳轉主要是通過UIApplication的openURL來實現的.
以Instagram(未提供SDK)為例:
//
// ViewController.m
#import ViewController.h
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *username = @icetime017;
[self openUserPage:username];
}
- (BOOL)isInstagramInstalled {
NSURL *instagramURL = [NSURL URLWithString:@instagram://location?id=1];
return [[UIApplication sharedApplication] canOpenURL:instagramURL];
}
- (void)openUserPage:(NSString *)username {
NSURL *fansPageURL;
if ([self isInstagramInstalled]) {
fansPageURL = [NSURL URLWithString:[NSString stringWithFormat:@instagram://user?username=%@, username]];
} else {
fansPageURL = [NSURL URLWithString:[NSString stringWithFormat:@http://instagram.com/%@, username]];
}
[[UIApplication sharedApplication] openURL:fansPageURL];
}
@end
即:
使用[[UIApplication sharedApplication] canOpenURL:instagramURL];來判斷是否已安裝該APP,
使用[[UIApplication sharedApplication] openURL:fansPageURL];來打開該APP, 若未安裝, 則默認在safari中打開相應頁面.