跳转APP(app之间互相通信)
下面来详细介绍实现的步骤:
1,添加URL Types项
a,展开URL types,再展开Item1,将Item1下的URL identifier修改为URL Scheme
b,展开URL Scheme,将Item1的内容修改为myapp
NSString *paramStr = [NSString stringWithFormat:@"myAppTest://username=%@&age=%@&address=%@", @"test123", @"100", @"上海市"]; NSURL *url = [NSURL URLWithString:[paramStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:url]; |
那么作为一个Provider怎么去接收Customer传递过来的参数呢?
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSString *urlStr = [url absoluteString]; if ([urlStr hasPrefix:@"myAppTest://"]) { NSLog(@"TestAppDemo1 request params: %@", urlStr); urlStr = [urlStr stringByReplacingOccurrencesOfString:@"myAppTest://" withString:@""]; NSArray *paramArray = [urlStr componentsSeparatedByString:@"&"]; NSLog(@"paramArray: %@", paramArray); NSMutableDictionary *paramsDic = [[NSMutableDictionary alloc] initWithCapacity:0]; for (int i = 0; i < paramArray.count; i++) { NSString *str = paramArray[i]; NSArray *keyArray = [str componentsSeparatedByString:@"="]; NSString *key = keyArray[0]; NSString *value = keyArray[1]; [paramsDic setObject:value forKey:key]; NSLog(@"key:%@ ==== value:%@", key, value); }
} return NO; }
|