zoukankan      html  css  js  c++  java
  • 通过openURL的方式启动其它App

    假设有两个App,项目名分别是SampleA和SampleB,需要在SampleA里点击一个Button来启动SampleB,并传递一个字符串。具体实现步骤如下:

    1. 在SampleB的info.plist文件里新增一个URL Schemes,并指定一个字符串,这个字符串就是调用App的链接名称:

     

    2. 在SampleA的按钮点击操作里执行下面代码:

    - (IBAction)openClickHandler:(id)sender
    {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myapp23://time_is_money"]];
    }

     

    3. 在SampleB的AppDelegate类里,调用系统事件处理传递过来的URL:

    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
    {
        NSString *strInfo = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:strInfo delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    
        [alertView show];
        
        return YES;
    }

    总结:

    1. 通过openURL的方式启动其它App时,地址格式为 @“URL Scheme://URL identifier”,其中URL identifier是可选的。

    2. URL identifier不能含有空格和问号。

    3. apple并不支持这种做法,实际产品开发中慎用。

  • 相关阅读:
    超有爱的并查集
    写给想当程序员的朋友
    POJ 1961 字符串 KMP (i-next[i])
    POJ 2406 KMP算法next数组理解
    POJ 2387 Bellman双重边
    POJ 1917 字符串替换
    POJ 1062 坑爹的聘礼(枚举等级差选择性找边)
    Linux下libxml2的使用
    浙大pat 1003
    判定一棵二叉树是否是二叉搜索树
  • 原文地址:https://www.cnblogs.com/CoderWayne/p/3794843.html
Copyright © 2011-2022 走看看