1

I have an iOS app and I get push notifications from my server. I've set content-available to be 1 in the json I'm sending to APNS and also set the flags for the background capabilities in my app.

The push notification comes, however when the app is in the background didReceiveRemoteNotification is not called - and I really need to, since I want to show a banner for my user.

Can anyone tell what I'm doing wrong?

Thanks

Notification:

aps = { alert = { "action-loc-key" = "This is button message"; body = "This is an iOS message"; }; badge = "-1"; sound = default; "content-available" = 1 };
The dude
  • 7,896
  • 1
  • 25
  • 50
Lior Z
  • 668
  • 1
  • 9
  • 21
  • Can you post the push body content, and I presume it does receive while in the foreground? Did you set the flags just in the Capabilites section? If so check they have gone into the info.plist - occasionally Xcode doesn't seem to populate the plist properly. – Gruntcakes Apr 17 '14 at 15:27
  • Yes, it does. aps = { alert = { "action-loc-key" = "This is button message"; body = "This is an iOS message"; }; badge = "-1"; sound = default; "content-available" = 1 }; – Lior Z Apr 17 '14 at 15:30
  • And I made sure Xcode placed the strings properly. – Lior Z Apr 17 '14 at 15:31
  • Get rid of the badge and set the sound to an empty string i.e. '' – Gruntcakes Apr 17 '14 at 15:31
  • Will it still make the sound? – Lior Z Apr 17 '14 at 15:40
  • No, but you can make the sound yourself can't you if you need to. – Gruntcakes Apr 17 '14 at 15:41
  • Well, I removed the sound and the badge, and now I actually don't get any notification (even when the app is in the foreground) – Lior Z Apr 17 '14 at 19:18
  • You must have messed something up somehow in the format. Are you sure you are clear on the difference between regular push notifications and background pushes. Seems to me you're not. – Gruntcakes Apr 17 '14 at 19:54
  • From your question and then subsequent comments its obvious you need to RTFM – Gruntcakes Apr 17 '14 at 19:58
  • @Piepants, would you be so kind to direct me to the manual that would help me? I have read this one: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html And it doesn't seem to be very helpful – Lior Z Apr 17 '14 at 20:22
  • @MartinH, what's the difference? From what I've read I should specify the background capabilities and the "content-available" flag, which I did. What am I missing? – Lior Z Apr 17 '14 at 20:26

1 Answers1

0

If application in background mode then method - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo won't be called automatically when push notification appears.
This method would be called only in case if user taps on push notification alert or banner.

Vlad Papko
  • 13,184
  • 4
  • 41
  • 57
  • So how am I supposed to make a banner show if the app is in the background but the phone isn't locked? Many apps do it, it's supposed to be very possible. – Lior Z Apr 17 '14 at 19:04
  • I think you need to go and actually read the apple documentation on push notifications and local notifications. You're complaining that the user isn't seeing the banner at the same time complaining you app isn't getting the push in the background. The OS doesn't do both. The answers are all in the Apple documentation. – Gruntcakes Apr 17 '14 at 19:53
  • Martin, I don't believe we understand each other; I don't need both, I actually need just one of those. If the banner would have been shown when the app is in the background (as it is shown when the screen is locked) - great, but it doesn't. If, the callback didReceiveRemoteNotification would have at least been called - I could have done it myself. So, not both. Just one of them. But both DON'T happen. So my question is - how is it that I'm supposed to raise the banner for my user? – Lior Z Apr 17 '14 at 20:02
  • @LiorZ if you don't see a banner and method didReceiveRemoteNotification is called then it seems that Apple Push Notification mechanism doesn't work for you at all. Did you configure it in Apple Developer Portal? – Vlad Papko Apr 17 '14 at 20:06
  • Yep. The mechanism works - since I do get notifications when the app is in the foreground. Even in the background I get the sound - but not the banner. – Lior Z Apr 17 '14 at 20:19
  • @LiorZ it seems that I understood the issue. Could you check notifications settings: System Settings -> Notification Center -> Find there your application icon -> Check if "ALERT STYLE" is set to "Banners" or "Alerts" and if option "Show in Notification Center" is switched on. Then try to resend push notification. – Vlad Papko Apr 17 '14 at 20:25
  • @LiorZ if Alert Style isn't set to "None" then I haven't any other ideas, sorry. – Vlad Papko Apr 17 '14 at 20:39
  • @VladimirPopko, funny thing my friend. When I checked - it was Banners, didn't change it - honestly! but after checking, it suddenly works. This is nice to see, but did I have to check? I don't want my users to have to check! Weird, sort of like a tree in the forest falling with noone hearing thing… – Lior Z Apr 17 '14 at 20:44
  • @LiorZ Generally users haven't to check it. When user runs your application first time iOS will provide alert view with request to add application to notification center. If user accepts then it will work out of the box. – Vlad Papko Apr 17 '14 at 20:48