How to send a silent Push Notification payload

后端 未结 2 1800
孤城傲影
孤城傲影 2020-11-29 00:19

I just want to know how I can determine what action to do on a silent push:

This is the aps that I sent to the client:

\"aps\": {
    \"         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 00:55

    As i understand, you want extra data inside payload, so you can identify what push notification type is,or what action need to be handled.

    For that edit your payload as:

     $body = array(
        'content-available' => 1,
        'sound' => ''
        );  
    
    $payload = array();
    $payload['aps'] = $body;
    $payload['action'] = 'order_update';
    

    Then in your iOS Code:

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
    
    
        NSString *action = userInfo["action"];
    
    
        if([userInfo[@"aps"][@"content-available"] intValue]== 1 && [action isEqualToString:@"order_update") //order update notification
        {
            //handle Your Action here
            return;
        }
    
    
    }
    

    Hope this solves your problem!

提交回复
热议问题