你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS --- APP之間相互跳轉

iOS --- APP之間相互跳轉

編輯:IOS開發綜合

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中打開相應頁面.

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved