码迷,mamicode.com
首页 > 移动开发 > 详细

IOS打开其他应用、以及被其他应用打开

时间:2015-11-04 13:12:14      阅读:1023      评论:0      收藏:0      [点我收藏+]

标签:

1、打开其他应用

     appURLStr = "cwork://app_id?title=xxx&content=xxx"

     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:appURLStr]];

  •      需要对方应用在Info.pist中配置:技术分享

     如此便能将对方应用调起。

 

 

2、被其他应用打开

     (1)同上图所示,需要自己在info.plist中配置,别人掉起自己,其中identifer没什么用,主要是URL Schemes,它会用来拼接被调起的url:如:cwork://xx-id?parame1 = "1" & parame2="2"

       a、程序已经运行时,会唤起appdelegate中的代理:

#define CWorkURLScheml      @"cwork://"
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    if (!url){
        return NO;
    }
    
    NSString *URLString = [url absoluteString];
    监听被谁调起
    if ([URLString rangeOfString:CWorkURLScheml].length > 0) {
    }
    return YES;
}

     b、 程序首次被启动时:    

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    NSURL *aLaunchOptionsURL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
    // 被其他应用唤醒监听,解析
    if ([aLaunchOptionsURL.absoluteString hasPrefix:CWorkURLScheml]) {
    }
	return YES;
}

  

(2) 然后url中带有参数,可以对url进行解析,以"?"为分隔符,对两边参数进行解析

+ (NSDictionary *)urlPropertyValue:(NSString *)aURLStr
{
    NSArray *aList = [aURLStr componentsSeparatedByString:@"?"];
    if (aList.count < 2) {
        return nil;
    }
    NSMutableDictionary *aDict = [NSMutableDictionary dictionary];
    NSString *rootPath = [aList objectAtIndex:0];
    [aDict setObject:rootPath forKey:@"rootPath"];
    NSString *aValueStr = [aList objectAtIndex:1];
    NSArray *aList1 = [aValueStr componentsSeparatedByString:@"&"];
    for (NSString *aStr in aList1) {
        NSArray *l = [aStr componentsSeparatedByString:@"="];
        if (l.count == 2) {
            NSString *k = [l objectAtIndex:0];
            NSString *v = [l objectAtIndex:1];
            [aDict setObject:v forKey:k];
        }
    }
    return aDict;
}

  

IOS打开其他应用、以及被其他应用打开

标签:

原文地址:http://www.cnblogs.com/yqlog/p/4935462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!