IOS 應用跳轉 (IOS9白名單)


跳轉到指定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;
}
復制代碼

 

效果圖七如下

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM