[英]Whatsapp integration and openURL issue in iOS 10
I have integrated whastapp in my iOS app. 我已经在我的iOS应用程序中集成了whastapp。 When I tested it in my iOS 10 device.
当我在iOS 10设备中对其进行测试时。 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.
任何帮助,将不胜感激。
You need to set LSApplicationQueriesSchemes
in plist if not set: 如果未设置,则需要在plist中设置
LSApplicationQueriesSchemes
:
Like, 喜欢,
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme1</string>
<string>urlscheme2</string>
</array>
Also, note that openURL(_:) is deprecated in iOS 10. 另外,请注意,iOS 10中不建议使用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:).
新的UIApplication方法openURL:options:completionHandler:是异步执行的,并在主队列上调用指定的完成处理程序(此方法替代了openURL :)。
New method in iOS 10
: iOS 10
新方法:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
Parameters: 参数:
The URL
to open 打开的
URL
An options dictionary (see below for valid entries). 选项字典(有关有效条目,请参见下文)。 Use an empty dictionary for the same behaviour as
openURL:
. 将空字典用于与
openURL:
相同的行为。
completion handler called on the main queue with the success. 完成处理程序成功调用主队列。
Nullable
if you are not interested in the status. 如果您对状态不感兴趣,则可
Nullable
。
Like, 喜欢,
UIApplication *application = [UIApplication sharedApplication];
[application openURL:URL options:@{} completionHandler:nil];
Example: 例:
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);
}
Read more here: 在这里阅读更多:
http://useyourloaf.com/blog/openurl-deprecated-in-ios10/ http://useyourloaf.com/blog/openurl-deprecated-in-ios10/
Edit:(Code based on iOS Version) 编辑:(基于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];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.