Phương pháp mới trong iOS 10:
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
đọc Doc đây:
https://developer.apple.com/library/prerelease/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html
mới phương pháp UIApplication openURL: tùy chọn: completionHandler :, mà được thực hiện không đồng bộ và cuộc gọi trình xử lý hoàn thành được chỉ định trên hàng đợi chính (phương thức này thay thế openURL :).
Đối dưới iOS 10:
[[UIApplication sharedApplication] openURL:URL];//URL is NSURL
Bạn có thể sử dụng mã dưới đây:
UIApplication *application = [UIApplication sharedApplication];
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 = [application canOpenURL:URL];
if(can){
[application openURL:URL];
}
}
Cũng cần phải thiết lập LSApplicationQueriesSchemes
trong plist nếu không được thiết lập:
Giống như,
<key>LSApplicationQueriesSchemes</key>
<array>
<string>urlscheme1</string>
<string>urlscheme2</string>
</array>
Cũng đọc trả lời ở đây: https://stackoverflow.com/a/40042291/5575752
Nguồn
2016-10-15 09:33:24
Tôi đang sử dụng openURL (url, tùy chọn, completionHandler) nên không chuyển đổi phương thức cởi mở với phương pháp openURL? – Vincent