Reputation: 707
My app using remote notification when we want to inform user that new data is available for his application ,In code I had written updateData method (which pulls data from server) in didReceiveRemoteNotification method of appDelegate. Now it works fine if my application is active, but not for inactive mode.Is I am wrong at somewhere ? what will be solution for that ? Thanks in advance.
Upvotes: 1
Views: 1000
Reputation: 125037
That's how notifications are supposed to work: if the app is the foreground app, it receives the notification directly; otherwise the user sees a message pop up asking if they want to activate the app. It's described clearly in the docs. You can't avoid that dialog if you want to use APNS.
Upvotes: 1
Reputation: 7238
I know of no way to handle push notifications even if your app is not in active state (And I think that's exactly the it should be)
You should check for PNS in your AppDelegate's didFinishLaunch as well
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//...
//If Push Notification
NSDictionary *pnsDict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(pnsDict != nil){
DDLogInfo(@"PNS");
[self handlePushNotification:pnsDict];
}
//..
}
This way you can be sure that you catch all remote notifications.
Be aware, that your app should not depend on pns
. PNS maybe fail to be delivered or the user can turn them off. The application should always work with pns enabled as well as pns disabled in the same way.
For more information read the Apple PNS Guide
Upvotes: 2