zoukankan      html  css  js  c++  java
  • IOS打开其他应用、以及被其他应用打开

    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;
    }
    

      

  • 相关阅读:
    java一个简单的线程池小例子
    java通过反射复制实体类
    java通过反射获取Object的属性
    java时间对比
    软件工程基础最后第一次作业 总结
    C++语言程序化设计——第五次作业
    软件工程基础——第四次作业
    C++语言程序化设计——第四次作业
    软件工程基础第三次作业——原型设计
    C++语言程序化设计——第三次作业
  • 原文地址:https://www.cnblogs.com/yqlog/p/4935462.html
Copyright © 2011-2022 走看看