Push Notifications without alert

前端 未结 6 1893
名媛妹妹
名媛妹妹 2021-01-01 04:56

Can I get push notifications without alert view? The idea in what service for game will send notifications as response for change game state (may be game state will store in

6条回答
  •  抹茶落季
    2021-01-01 05:38

    Why not!

    You can send a hidden push notification without any alert, banner or sound.

    PHP CODE

    without a text:

    $payload['aps'] = array('badge'=> 0, 'sound' => 'default');
    

    Without text and sound

    $payload['aps'] = array('badge'=> 0);
    

    and on your ios end you can make a condition for this:

    //Receiving a Push Notification
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
        NSMutableDictionary *pushNotiFicationDict = [userInfo objectForKey:@"aps"];
        NSLog(@":%@", pushNotiFicationDict);
    
        if([pushNotiFicationDict objectForKey:@"alert"])
        {
            // when push notification has text
            UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"MESSAGE" message:[pushNotiFicationDict objectForKey:@"alert"]
                                                            delegate:nil
                                                   cancelButtonTitle:@"ok"
                                                   otherButtonTitles:nil];
            [alert show];
        }
        else
        {
            // when push notification does not have text
        }
    }
    

    But i think you can not perform any action if application is not running or running in background.

提交回复
热议问题