-canOpenURL: failed for URL: "kindle://home" - error: "This app is not allowed to query for scheme k

iOS 从C APP里启动 D APP 

首先在D APP里设置 URL Schemes 

在info.plist 文件里添加URL Schemes 

URL Types -->item0 --> URL Schemes --> TestD 

 

然后再回到C APP 找到info.plist 文件

添加 LSApplicationQueriesSchemes  --> item0  TestD

D程序

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

    NSString *str=[NSStringstringWithFormat:@"url:%@,source application:%@,params:%@",url,sourceApplication,[urlhost]];

    NSLog(@"%@",str);

    UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:[url host]delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil,nil];

    

    [alert show];

    

    return YES;//是否打开

}



C程序

NSString *url=@"TestD://MyNameIsHanMeiMei";

    [self openUrl:url];


-(void)openUrl:(NSString *)urlStr{

    //注意url中包含协议名称,iOS根据协议确定调用哪个应用,例如发送邮件是“sms://”其中“//”可以省略写成“sms:”(其他协议也是如此)

    NSURL *url=[NSURLURLWithString:urlStr];

    UIApplication *application=[UIApplicationsharedApplication];

    if(![application canOpenURL:url]){

        NSLog(@"无法打开\"%@\",请确保此应用已经正确安装.",url);

        return;

    }

    [[UIApplicationsharedApplication] openURL:url];

}



你可能感兴趣的:(程序跳转)