iOS 10中的Whatsapp集成和openURL问题 [英] Whatsapp integration and openURL issue in iOS 10
问题描述
我已经在我的iOS应用中集成了whastapp。当我在iOS 10设备中测试它时。它崩溃了一个问题。
I have integrated whastapp in my iOS app. When I tested it in my iOS 10 device. It crashes with an issue.
快照未渲染的视图会导致空快照。确保您的视图在屏幕更新后的快照或快照之前至少呈现一次。
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
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];
}
可能是什么问题。任何帮助将不胜感激。
What might be the issue. Any help would be appreciated.
推荐答案
您需要设置 LSApplicationQueriesSchemes
in plist如果没有设置:
You need to set LSApplicationQueriesSchemes
in plist if not set:
赞,
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme1</string>
<string>urlscheme2</string>
</array>
另请注意 openURL(_ :) 在iOS 10中已弃用。
Also, note that openURL(_:) is deprecated in iOS 10.
新的UIApplication方法openURL:options:completionHandler:,其中
是异步执行的,并在主队列上调用指定的完成处理程序
(此方法替换openURL :)。
The new UIApplication method openURL:options:completionHandler:, which is executed asynchronously and calls the specified completion handler on the main queue (this method replaces openURL:).
iOS 10中的新方法
:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
参数:
-
要打开的
URL
选项字典(有效条目见下文)。使用空字典表示与 openURL:
相同的行为。
An options dictionary (see below for valid entries). Use an empty dictionary for the same behaviour as openURL:
.
在主队列上调用完成处理程序随着成功。 Nullable
如果您对状态不感兴趣。
completion handler called on the main queue with the success. Nullable
if you are not interested in the status.
比如,
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];
}
}
这篇关于iOS 10中的Whatsapp集成和openURL问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!