gpt4 book ai didi

ios - iOS 10 中的 Whatsapp 集成和 openURL 问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:22:50 27 4
gpt4 key购买 nike

我已将 whastapp 集成到我的 iOS 应用程序中。当我在我的 iOS 10 设备上测试它时。它因问题而崩溃。

对尚未渲染的 View 进行快照会生成空快照。确保您的 View 在屏幕更新之前或快照之前至少被渲染过一次。

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];
}

可能是什么问题。任何帮助将不胜感激。

最佳答案

如果未设置,则需要在 plist 中设置 LSApplicationQueriesSchemes:

喜欢,

<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme1</string>
<string>urlscheme2</string>

</array>

另外,请注意 openURL(_:)在 iOS 10 中已弃用。

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: 相同的行为,使用空字典。

  • 成功调用主队列的完成处理程序。 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];

}

}

关于ios - iOS 10 中的 Whatsapp 集成和 openURL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40040853/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com