简体   繁体   中英

iOS7 Silent Push notification not working

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!!!

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.

在此处输入图片说明

or

在此处输入图片说明

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);
 }

Try with a integer value :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM