HandleOpenURL not called using custom URL scheme in iPhone OS

I have successfully added my own url schemes to my application. The application starts correctly using circuits.

Now I want to process incoming data, but the delegate is not called. This is a universal application, and I added the following function to AppDelegates:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { if (!url) { return NO; } NSString *URLString = [url absoluteString]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"test message", nil) message:URLString delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; [alert release]; return YES; } 

I am testing a scheme: myapp: //appalarm.com ... and would expect to be appalarm.com in a URLString

What is wrong with him?

Thank you for your responses!

+4
source share
3 answers

If your application delegate implemented "applicationDidFinishLaunchingWithOptions:", then the "handleOpenURL:" method will never be called. Look at the parameters that went through another method to determine how your application was launched and what behavior you should implement.

+5
source

I tried to clarify in yet another post . Ashley Clark's answer is only partly right. On OS 4.0, the handleOpenURL handle is called (at least for file URLs), and you must implement it to handle calls with an open URL when the application is in the background. Thus, opening a file in both methods can open it twice (if applicationDidFinishLaunchingWithOptions returns YES what it should). See another post .

+7
source

Try entering the code below the function

 -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if (!url) { return NO; } NSString *URLString = [url absoluteString]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"test message", nil) message:URLString delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; [alert release]; return YES; } 
+1
source

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


All Articles