Ios 打开第三方应用传值

2017-06-07  本文已影响30人  透支未来

#pragma mark 设置系统回调
// 支持所有iOS系统
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{

   NSLog(@"%@", url);
    
    if ([[url scheme] isEqualToString:@"myurltest"])
    {
        //处理链接
        NSString *text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"新消息" message:text delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil];
        [myAlert show];
        
        return YES;
    }
    
    return NO;
}

//仅支持iOS9以上系统,iOS8及以下系统不会回调
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
NSLog(@"%@", url);
    
    if ([[url scheme] isEqualToString:@"myurltest"])
    {
        //处理链接
        NSString *text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"新消息" message:text delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil];
        [myAlert show];
        
        return YES;
    }
    
    return NO;
}
//支持目前所有iOS系统
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
   NSLog(@"%@", url);
    
    if ([[url scheme] isEqualToString:@"myurltest"])
    {
        //处理链接
        NSString *text = [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"新消息" message:text delegate:self cancelButtonTitle:@"知道了" otherButtonTitles: nil];
        [myAlert show];
        
        return YES;
    }
    
    return NO;
}
上一篇下一篇

猜你喜欢

热点阅读