Push Notifications without alert

2019-02-10 18:37发布

问题:

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 database), if this is impossible, what you can suggest about how me send new game state to each connected game client as response of changing game state.

Game will be developing for iPad.

Thanks, Roman

回答1:

No, a push notification will always display a notification as it requires user consent to wake up or launch your application. However if your Application is in the foreground and running, the push notification will not appear and your app can handle the message that the push notification has. All of the preceding applies to local notifications aswhile.

I don't know what you mean by game state. But just have your app listen in on a script on your server which will pass information to your app. Edit: Or like I said above if your app is open in the foreground, push notifications won't appear on screen and you can send information that way. However if you want to do it in the background its not possible no matter what unless you are truly multitasking (GPS, VOIP, Music) or you have user consent through push notification.



回答2:

For me @Ajay answer is not correct (sorry).

With push notification you can choose between three user options: text message (alerts), sounds and badges. Every push notification can contain one or more of these options, so you can send for example a notification with sound and badge, but without message and in this case any alert is shown.

Note that you can even pass hidden options in a private dictionary to your application.



回答3:

Use content-available property:

The aps dictionary can also contain the content-available property. The content-available property with a value of 1 lets the remote notification act as a “silent” notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html



回答4:

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.



回答5:

You can handle notifications in app and store data in DB, or instead show a message but when app is not running NO.



回答6:

I agree with @MacTeo. You can delivery a push notification with a payload that contains only one attribute (Sound, Alert (or message) and badge.

With your requirement, keep track of the users device on the server when they open and close the app (foreground and background). If something happens then you can check to see the device's state on the server. You could then decide on how to construct a notification (if any is necessary) base on the last reported state of the device.

Just spitballing:

You could, if you wanted to (however, it isn't what the APNs is designed to do), deliver a push notification with only a badge count = 0 and pass some extra dictionary data with it. That would not alert the user and could be handled in the app if it was in the foreground.