5

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

Roman Shkarin
  • 177
  • 1
  • 2
  • 14
  • 1
    YES, we CAN do it (as of now ). See this SO question : http://stackoverflow.com/questions/15225677/ios-push-notifications-update-badge-without-alert – S.Philip Jun 19 '14 at 05:15
  • 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 – AZ_ Nov 25 '14 at 10:08

6 Answers6

18

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.

MacTeo
  • 2,656
  • 1
  • 20
  • 23
  • 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. – Ajay Feb 27 '11 at 22:42
8

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

Andriy Kopachevskyy
  • 7,276
  • 10
  • 47
  • 56
  • 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. – Tim Feb 04 '15 at 01:06
5

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.

Community
  • 1
  • 1
Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
3

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.

Ajay
  • 2,078
  • 1
  • 15
  • 13
  • 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 – AZ_ Nov 25 '14 at 10:07
  • @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? – abhimuralidharan Feb 15 '16 at 08:21
0

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.

hylander0
  • 1,091
  • 11
  • 25
0

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

elitalon
  • 9,191
  • 10
  • 50
  • 86
Fa.Shapouri
  • 988
  • 2
  • 12
  • 30