IOS 應用跳轉 (IOS9白名單),iosios9
跳轉到指定app的實現
IOS中應用的跳轉是通過URL實現的,因此在實現應用跳轉之前我們要設定一下對應的URL。
圖一(尋找配置軟體的URL)
圖二(具體配置選項)
注意:
如果IOS版本為IOS9 我們需要為app設定白名單。
實現跳轉的前提是有這個app,因此我們需要把被跳轉的app先運行,即安裝到模擬器中。
三(在info中添加)
四
代碼:
//// ViewController.m// X//// Created by ma c on 16/4/9.// Copyright © 2016年 bjsxt. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIButton *button;@end@implementation ViewController- (IBAction)GoU:(id)sender { //擷取跳轉app的URl NSURL * url = [NSURL URLWithString:@"U://"]; //判斷手機中是否安裝了對應的app if ([[UIApplication sharedApplication] canOpenURL:url]) { //開啟應用程式 [[UIApplication sharedApplication]openURL:url]; }}- (void)viewDidLoad { [super viewDidLoad];}@end
為了證明實現的是app之間的跳轉:另附兩張app的故事板
X:圖五
U:圖六
跳轉到指定頁面的實現
前提:我們想要從X跳轉到U的朋友圈。
那麼X的代碼如下:
//// ViewController.m// X//// Created by ma c on 16/4/9.// Copyright © 2016年 bjsxt. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIButton *button;@end@implementation ViewController- (IBAction)GoU:(id)sender { //擷取跳轉app的URl NSURL * url = [NSURL URLWithString:@"U://"]; //判斷手機中是否安裝了對應的app if ([[UIApplication sharedApplication] canOpenURL:url]) { //開啟應用程式 [[UIApplication sharedApplication]openURL:url]; }}- (IBAction)GoFriend:(id)sender { //擷取跳轉朋友圈的URl NSURL * url = [NSURL URLWithString:@"U://friend"]; //判斷手機中是否安裝了對應的app if ([[UIApplication sharedApplication] canOpenURL:url]) { //開啟朋友圈 [[UIApplication sharedApplication]openURL:url]; }}- (void)viewDidLoad { [super viewDidLoad];}@end
我們不能僅僅對X進行設定更要對U進行設定。
對U的代碼操作在Appdeledate中。
代碼如下:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{ //將url轉為字串 NSString * urlString = url.absoluteString; //判斷是通過什麼跳轉過來的 if ([urlString containsString:@"friend"]) { NSLog(@"在這裡執行頁面跳轉即可。"); } return YES;}
七如下