aneuryzm
aneuryzm

Reputation: 64874

iOS: Push notifications work only if the app run in foreground

I have 2 iPhones and I'm testing Apple push notifications.

They perfectly work when my app is running in foreground on both devices. But if I close it, by clicking on the Home button, I don't receive the notifications anymore.

The system doesn't show the notification popup. And I think this doesn't depend on my app code...

So far I've implemented

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

and it works great when the app is in foreground. I've also implemented:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

but the launchOptions never contain the notification. However, this is correct, I guess, because the last method is invoked when I select a button of a notification alert that I never see...

thanks

Upvotes: 0

Views: 2771

Answers (1)

Nekto
Nekto

Reputation: 17877

When you call method - (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types you should indicate appropriate type of argument. If you want to display alert when system receive push-notification for your device then you should pass UIRemoteNotificationTypeAlert.

Also you can combine types and pass it in that argument: UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge.

Upvotes: 1

Related Questions