Senthilkumar
Senthilkumar

Reputation: 2481

APNS notification received but not display

I am trying to implement pushnotification. I get pushed message when app is running state.

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

NSLog(@"\n\n\n apns==%@\n\n\n",userInfo);


}

my problem is when I pushed message when app is not running means badge count only show on the app icon. It will not display the alert like close and view buttons. Even I cont predict

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

    NSLog(@"\n\n\n\apns==%@\n\n\n\n",launchOptions);
}

I checked also in settings --> Notifications --> myApp --> choose badges, sounds, alerts

I'm using config below:

Mac os 10.9

xcode 5.0.2

ios 7.0

Please advice me.

I want this message.

enter image description here

Thanks in advance.

Upvotes: 4

Views: 6818

Answers (3)

Nitin Gohel
Nitin Gohel

Reputation: 49730

You have to setting Alert view for Displaying your coming Push notification Message like:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if (application.applicationState == UIApplicationStateActive)   
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"App Notification" message:[NSString stringWithFormat:@"%@",[[userInfo objectForKey:@"aps"] objectForKey:@"alert"]]delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
}

when your application in Background Mode or close then that manager by apple you can't handle it. you have to setting Alert prompt from device-->setting. And you badge Display because that automatically functionality of you badge count it's an integer value so that setting automatically. just set push notification setting from device--> setting-->Notification Center--->find your App--->select it and that display like:

enter image description here

UPDATE:

Your push Notificaton Payload JSON formate should look like this:

{
    "aps": {
         "badge": 10,
         "alert": "Hello world!",
         "sound": "cat.caf"
    }
}

Upvotes: 3

Brian
Brian

Reputation: 1

I just got same problem and I have found issues and fixed. You need to check value of alert on

{
    "aps": {
         "badge": 1,
         "alert": "your value!",
         "sound": "default"
    }
}

I think "your value" is null when you call json_encode.

Upvotes: 0

staticVoidMan
staticVoidMan

Reputation: 20274

When app is closed and it gets a push notification then the push notification is available in the launchOptions parameter in -didFinishLaunchingWithOptions:

You can access it this way:

//when app is closed initially but launched after tapping on the push notification 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if (launchOptions) { //launchOptions is not nil
        NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];

        if (userInfo) { //userInfo is not nil
            NSLog(@"%@",userInfo);
        }
    }
    return YES;
}

//when app is in background or active
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSLog(@"%@",userInfo);
}

ref: my answer on a similar question: Push Notification -didFinishLaunchingWithOptions

Upvotes: 1

Related Questions