Search code examples
objective-cios7nslog

NSLog from appDelegate


Inside AppDelegate.m I am trying to grab the stuff from a string I am getting from an incoming URL. I'm not sure why NSLog is not printing anything out...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions openURL:(NSURL *)url
{
    // incoming URL...
    // i.e.  palsvid://blabla.com/foo.php?request=laa&id=1004


    NSString *q = [url query];

    NSLog(@"%@",q); // Does not log anything! Even with a hard coded string!

    NSArray *pairs = [q componentsSeparatedByString:@"&"];
    // ...

Am I doing something wrong? I update plist to accept the url, now I want to parse it.

Eventually I will take this data and use it in my ViewController. NSLog works in the ViewController methods...

Thanks


Solution

  • You have the wrong method signature so your method is never called. There is no openURL: parameter. You want:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // your code here
    }
    

    That is called when you app is started from scratch.

    To handle your app being called from another app or being sent a URL, you need to implement the following:

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        // process URL here
    }
    

    Please read the docs for UIApplicationDelegate as well as the related app life cycle docs.