Push Notifications without alert

15,989

Solution 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.

Solution 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.

Solution 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

Solution 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.

Share:
15,989
Roman Shkarin
Author by

Roman Shkarin

Updated on June 04, 2022

Comments

  • Roman Shkarin
    Roman Shkarin almost 2 years

    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

  • Ajay
    Ajay about 13 years
    While this is true his goal isn't to alert the user, he wants to pass a game state. He can't pass a game state through an alert sound, or badge number. Also, it seems like he wants is a constant stream of data getting to his app, which would best be served through a server side script. Also if an alert sound, or badge shows, his app would not wake up if in the background and his game state would fail to deliver on time.
  • AZ_
    AZ_ over 9 years
    In iOS7 there is new type of push notification added, where user does not see any alert but application can be waked up in background to fetch data from server. Yet to see that in action
  • Tim
    Tim over 9 years
    Perfect! Exactly what I was looking for. Far better than the older answers. However, please note that this property only works for iOS7 and above.
  • abhimuralidharan
    abhimuralidharan about 8 years
    @AZ_ What are you talking about?I want to run some code in background every 24 hours even if the app is in background.How can I do that?