0
votes

I have implement push notifications in iOS7. As iOS7 having features of receiving push notification silently by using method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo performFetchWithCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler
{
}

But this method never getting called as I am sending notification. I am receiving the notification in notification tray But notification should not be there as It is silent. I am using Raywenderlich's PHP code to send the push Notification. I have added content-available key also like this

// Create the payload body

$body['aps'] = array(
    'content-available' => '1',
    'alert' => $message,
    'sound' => 'default'
    );

Please Help!!!

2
There are several reasons for that, first check your server log that is it able to send the message successfully to Apple server? or you are having this problem only in IOS 7Retro
Are you sure you have the correct certificate and device token? In debug mode you need to use the debug certificate and the device token is different than the one you have in production. Also if you want a push to be silent, the sound value should be omitted AFAIK. Finally you can test pushes easy, by using Urbanairship instead of writing your own php implementationLefteris
I am receiving the notification.. no issue in that... But not receiving silent notificationGopesh Gupta
I dont want to show the notification to user..Gopesh Gupta
If you don't want to show notification just ignore the "alert" in your payload.Nandha

2 Answers

3
votes

You should not add 'alert' param in your payload if you want to silent push notification.

pass your param like this.

$body['aps'] = array(
'content-available' => '1'
);

And verify you enabled remote-notification in your project plist.

enter image description here

or

enter image description here

You will get notification by implementing this delegate.

 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
// Call or write any code necessary to download new data.
completionHandler(UIBackgroundFetchResultNewData);
 }
1
votes

Try with a integer value :

$body['aps'] = array(
    'content-available' => 1,
    'alert' => $message,
    'sound' => 'default'
    );