MD SHAHIDUL ISLAM
MD SHAHIDUL ISLAM

Reputation: 14523

Push Notification not receiving in background but working in foreground

When my app is in foreground It can receive push notification in

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

    NSLog(@"%@",userInfo);

}

Log in console -

{

    app =     {

        alert = dsafdas;

        badge = 1;

        sound = "myringtone.caf";

    };

}

But the problem is when the app is in background not showing push notification.

In the settings for the app

ALERT STYLE - Banners

Badge App Icon - enabled

Sounds - enabled

What is the problem?

Upvotes: 0

Views: 1082

Answers (3)

Asfanur
Asfanur

Reputation: 245

didReceiveRemoteNotification

Will work for sure(Like database operation or Network access). But it will not display log output until the app is in foreground.

N.B: To work on background you need to turn on the capabilities feature.

Upvotes: 0

meda
meda

Reputation: 45500

didReceiveRemoteNotification gets called in foreground, when in bacground mode, user needs to tap to make the app active.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive ){
      NSLog(@"app was already in the foreground");
    }
    else{
       NSLog(@"app was just brought from background to foreground");
    }
    NSLog(@"%@",userInfo);
}

Upvotes: 2

MD SHAHIDUL ISLAM
MD SHAHIDUL ISLAM

Reputation: 14523

Problem is: app should be aps

{
    aps :  {

Instead of

{
    app :  {

Upvotes: 3

Related Questions