0

I am having an iOS application where I am receiving Push Notifications. I have the following code in AppDelegate

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    if ( application.applicationState == UIApplicationStateActive )
    {
       // app was already in the foreground
    }
    else
    {
          NSLog(@"Received push notification");
    }

}

I am running the app in Xcode with my iPhone. When the app is in background I am able see the NSLog when the notification comes.

When I close the app i.e removing it from opened apps in iOS the debugger session in Xcode stops and I can't see the NSlog after that even after receiving notification on my iPhone for the app when the app is closed (Push Notifications can come to app even if it is closed)

How can I print logs when the app is being opened from closed state?

Raghav
  • 8,772
  • 6
  • 82
  • 106
  • Possible duplicate of [How debug after closing application](http://stackoverflow.com/questions/22782873/how-debug-after-closing-application) – Teja Nandamuri Mar 03 '16 at 15:30

1 Answers1

0

It sounds like you're describing a few different things here.

First, you won't be able to see any NSLog notification messages if/after the app is fully terminated, until the app is launched by some mechanism.

If you want to print logs when the app is being opened from a terminated state, you can do something like the following:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // ...
    NSLog(@"%s", __PRETTY_FUNCTION__); // print the function name

    // Process remote notifications
    NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    if (remoteNotification) {
      [self processNotification:remoteNotification];
    }
}

- (void)processNotification:(NSDictionary *)payload {
     NSString *someString = [payload objectForKey:@"someStringKey"];

     // do something!
}
JaredH
  • 2,338
  • 1
  • 30
  • 40
  • Thanks for your reply. Will I be able to get the data ((NSDictionary *)userInfo) from the notification clicked in "didFinishLaunchingWithOptions" method. – Raghav Mar 03 '16 at 15:47
  • When the app is closed. Xcode debugging is turned off. Notification comes, I click it and no "ns log" is logged after that. Can you help me logging even if the debugging is turned off by Xcode? – Raghav Mar 03 '16 at 17:54