Whatsapp integration and openURL issue in iOS 10

I integrated whastapp in my iOS app. When I tested it on my iOS 10 device. It crashes with the problem.

A snapshot of a snapshot that was not displayed results in an empty snapshot. Make sure your view has been viewed at least once before the snapshot 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 could be the problem. Any help would be appreciated.

+2
source share
1 answer

You need to install LSApplicationQueriesSchemes in plist, if not set:

how

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

Also note that openURL (_ :) is deprecated in iOS 10.

The new UIApplication method is openURL: options: completeHandler:, which runs asynchronously and calls the specified completion handler in the main queue (this method replaces openURL :).

New method in iOS 10 :

 - (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion 

Options:

  • URL to open

  • Dictionary of options (see below for valid entries). Use an empty dictionary for the same behavior as openURL:

  • a call completion handler in the main queue with success. Nullable if you are not interested in status.

how

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

More details here:

http://useyourloaf.com/blog/openurl-deprecated-in-ios10/

Edit: (code based on iOS version)

 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]; } } 
+5
source

Source: https://habr.com/ru/post/1258250/


All Articles