问题
I am trying to open link in Safari browser from inside my iOS app. Its a hybrid app so I made changes in iOS native side (which I am totally unfamiliar with)
I have tried this code from below posts: Open target="_blank" links outside of UIWebView in Safari
NSLog(@"open safari");
// NSLog(urlSafari);
// [[UIApplication sharedApplication] openURL:urlSafari];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[request.URL.absoluteString substringFromIndex:7]]];
//[NSURL URLWithString:@"http://apple.com"] options:@{} completionHandler:nil];
return NO;
This code works fine in 6/10 cases, 4cases it gives below error and stops navigating to safari browser. If I load the same page again in App and then it works fine. Other time it won't.
Error it gives me when clicking these links: 2019-10-29 12:07:35.341 AppName[62467:679879] open safari
2019-10-29 12:07:35.363 AppName[62467:679879] -[NSURL _fastCStringContents:]: unrecognized selector sent to instance 0x60000006ed50
2019-10-29 12:07:35.363 AppName[62467:679879] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: -[NSURL _fastCStringContents:]: unrecognized selector sent to instance 0x60000006ed50
2019-10-29 12:07:36.045 AppName[62467:679879] DataManager saveAppData appData:<>|
2019-10-29 12:07:36.249 AppName[62467:679879] Can't end BackgroundTask: no background task exists with identifier 22 (0x16), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
From all search I've done, it points to NSURL validation or some wrong value is being passed which not able to pass through NSURL validation. but not sure how to fix this
来源:https://stackoverflow.com/questions/58612520/nsurl-fastcstringcontentssome-link-url-giving-error-when-trying-to-open-from-i