我已经在我的iOS应用中集成了whastapp。当我在iOS 10设备上测试它时。它崩溃了一个问题。
快照未呈现的视图会导致空快照。确保在屏幕更新后快照或快照之前,您的视图至少呈现过一次。
NSURL *whatsappURL = [NSURL URLWithString:[NSString stringWithFormat: @"whatsapp://send?abid=%@&text=WelcomeToChatBought",[abidArray objectAtIndex:buttonclicked.tag-1000]]];
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL])
{
[[UIApplication sharedApplication] openURL: whatsappURL];
}
可能是什么问题。任何帮助将不胜感激。
答案 0 :(得分:5)
如果未设置,则需要在plist中设置LSApplicationQueriesSchemes
:
像,
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme1</string>
<string>urlscheme2</string>
</array>
另请注意,iOS 10中已弃用openURL(_:)。
新的UIApplication方法openURL:options:completionHandler:,其中 以异步方式执行并调用指定的完成处理程序 在主队列上(此方法替换openURL:)。
iOS 10
中的新方法:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
参数:
要URL
打开
选项字典(有效条目见下文)。使用空字典表示与openURL:
相同的行为。
完成处理程序在主队列上调用成功。如果您对状态不感兴趣,请Nullable
。
像,
UIApplication *application = [UIApplication sharedApplication];
[application openURL:URL options:@{} completionHandler:nil];
示例:
NSString *scheme=[NSString stringWithFormat: @"whatsapp://send?abid=%@&text=WelcomeToChatBought",[abidArray objectAtIndex:buttonclicked.tag-1000]]];
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open %@: %d",scheme,success);
}];
} else {
BOOL success = [application openURL:URL];
NSLog(@"Open %@: %d",scheme,success);
}
在这里阅读更多内容:
http://useyourloaf.com/blog/openurl-deprecated-in-ios10/
编辑:(基于iOS版本的代码)
NSURL *URL = [NSURL URLWithString:strUrl];
if([[UIDevice currentDevice].systemVersion floatValue] >= 10.0){
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open %@: %d",scheme,success);
}];
} else {
BOOL success = [application openURL:URL];
NSLog(@"Open %@: %d",scheme,success);
}
}
else{
bool can = [[UIApplication sharedApplication] canOpenURL:URL];
if(can){
[[UIApplication sharedApplication] openURL:URL];
}
}