-3

I have following setup, when i open my app (app number 2 open by app number 1 using url) using url in iPhone 7, then i am not getting any url inputs.

its not showing any alert box at all. How do i check if i am receiving the url input in my app at all or not?

AppDelegate.m:

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

ViewController.m:

-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //if (url != nil && [url isFileURL]) {
    //[self.ViewController handleOpenURL:url];
    //}
  id test = (NSURL *) url;
  UIAlertController * alert=   [UIAlertController
                                alertControllerWithTitle:@"My Title"
                                message:test
                                preferredStyle:UIAlertControllerStyleAlert];

  [self presentViewController:alert animated:YES completion:nil];
  //NSLog(@">>> got <<< >>> <<< !!!! >>>> : %@", url);
  return YES;
}

- (void)viewDidLoad {
  [super viewDidLoad];
}

1 Answers1

1

The problem is that

-(BOOL) application:(UIApplication *)application 
    openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

... is a UIApplicationDelegate method. So it can't be located in ViewController.m. It needs to be in AppDelegate.m.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I put that now in AppDelegate.m but one error i am getting `/Users/sun/Desktop/iphone/AppDelegate.m:16:9: No visible @interface for 'AppDelegate' declares the selector 'presentViewController:animated:completion:'` –  Feb 20 '17 at 01:03
  • 2
    Sure, you'll have totally different errors. But that's not what you asked. The problem was "then i am not getting any url inputs". Well, now you are! So that problem is solved. Done. Take out the `present` stuff and put the `NSLog` back in, and you will see. – matt Feb 20 '17 at 01:05