iOS兩個APP之間跳轉傳值


==================執行跳轉的APP=================數組

//app

//  ViewController.mide

//  系統應用跳轉atom

//url

//  Created by dc0061 on 16/1/6.spa

//  Copyright © 2016 dc0061. All rights reserved..net

//3d


#import "ViewController.h"code


@interface ViewController ()orm


- (IBAction)search:(id)sender;


@property (weak, nonatomic) IBOutlet UITextField *strUrl;


- (IBAction)jumpApp:(id)sender;


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


#pragma mark 跳轉到網頁

- (IBAction)search:(id)sender {

    NSString *str = _strUrl.text;

   [self openUrl:str];

}


//跳轉到別的安裝的應用---7.0之前須要增長一個白名單:增長方法,在plist文件裏面增長一個LSApplicationQueriesSchemes節點,類型是array,在數組裏面增長一個子項目,將你要跳轉的那個應用設置的 URL Schemes填寫在裏面

//URL Schemes 設置方法,被跳轉的應用裏點擊項目名稱-->info-->底部URL Types點開,在裏面增長一項而且給URL Schemes添加一個名稱

//7.1 以後須要在給identifier 設置一個名稱,而且跳轉的應用 General-->Bundle identifler須要設置一個名稱,而且要和被跳轉應用identifier裏面設置的名稱一致


#pragma mark 跳轉到app

- (IBAction)jumpApp:(id)sender {

    NSString *str = @"app://name=jack";

    [self openUrl:str];

    

}


- (void) openUrl : (NSString *) strUrl{

    NSURL *url = [NSURL URLWithString:strUrl];

    UIApplication *app = [UIApplication sharedApplication];

    //判斷手機裏面是否安裝該應用

    if (![app canOpenURL:url]) {

        NSLog(@"沒法打開%@,請確保應用已正確安裝",url);

    }else{

        //打開應用

        [app openURL:url];

    }

}


@end



=================被跳轉的app=================

//AppDelegate 裏面添加以下代碼

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window.backgroundColor = [UIColor whiteColor];

    self.viewcon = [[ViewController alloc]init];

    self.window.rootViewController = self.viewcon;

    return YES;

}

//從另一個app 裏面跳過來時會執行的方法

- (BOOL) application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{

    self.viewcon.label.text=[NSString stringWithFormat:@"%@",url];//給頁面裏面的控件賦值

    return YES;

}

相關文章
相關標籤/搜索