欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS實現app間跳轉功能

 更新時間:2018年05月27日 15:17:07   作者:specter_hhg  
這篇文章主要為大家詳細介紹了iOS實現app間跳轉功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文為大家分享了iOS實現app間跳轉功能的具體代碼,供大家參考,具體內容如下

我們通過系統(tǒng)的openURL方法,可以從當前的app跳轉到其他任意app去,包括系統(tǒng)自帶的、以及我們開發(fā)的app。

本文模擬A app跳轉到 B app

A app代碼:

// A app
// ViewController.m
// 程序跳轉
//
// Created by hhg on 15/10/23.
// Copyright (c) 2015年 hhg. All rights reserved.
//

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  // 為我們的程序設置一個唯一的標識,那么其他軟件就可以使用openURL方法通過唯一標識來打開我們的程序
  [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"zapp:"]];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
}
@end

B app代碼:

// B app
// AppDelegate.m
// MyApp
//
// Created by hhg on 15/10/23.
// Copyright (c) 2015年 hhg. All rights reserved.
//

#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  return YES;
}

// 當其他程序通過openURL打開該程序的時候,會觸發(fā)這個方法
// URL ,就是其他程序打開時候的URL
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"跳轉成功!" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles: nil];
  [alertView show];
  return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

- (void)applicationWillTerminate:(UIApplication *)application {
}
@end

B app 在info.plist 文件里面需要設置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
  <dict>
    <key>CFBundleURLName</key>
    <string></string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>zapp</string>
    </array>
  </dict>
</array>
</plist>

如圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論