0

Let's assume a scenario in which there is a chat app and I opened it and then pressed home button. Now app is running in background but not killed. Can i receive notification badges or pop ups for any upcoming messages? For e.g: If there is a new message and my app produces some sound or badge if it's not killed and running in background.

I am asking this question as i am in doubt. I have found online that app can run in background only for few enumerated list of tasks predefined by Apple, not in all cases like android.

Please tell me whether i can get notified about new messages in this case or not. (without server, push notifications use). More clearly what i want is to have local notifications once app is in the above mentioned scenario. Kindly tell me if it's possible.

Thanks in advance.

Jacob Kaif
  • 149
  • 1
  • 1
  • 8
  • See [this question](https://stackoverflow.com/questions/37933387/firebase-cloud-messaging-doesnt-create-push-notifications-but-gets-information/38445657#38445657) and also [this question](https://stackoverflow.com/questions/39914557/push-notification-not-showing-in-ios-10). There's plenty of info there to give you direction. The actual instructions for setting it up are in the [Receive Messages in an iOS App guide](https://firebase.google.com/docs/cloud-messaging/ios/receive) – Jay Aug 05 '17 at 16:34

1 Answers1

0

You can use VoIP push notifications to achieve just this. You can run some code in the background to handle notifications in the background and then when your app decides play a local notification.

However, as of June apple is no longer allowing developers to use the API this way, except from WhatsApp Because $$ I guess.

You'll need to use PushKit:

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType)

func voipRegistration() {
        let voipRegistry: PKPushRegistry = PKPushRegistry(queue: DispatchQueue.main)
        voipRegistry.delegate = self
        voipRegistry.desiredPushTypes = [PKPushType.voIP]
    }
Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52
  • Antwa, thanks for your reply. You mean what i want to do above is not possible without push notifications i.e i can not make my app show any notification for any message arrived after i pressed home button and app goes in background. Right? – Jacob Kaif Aug 05 '17 at 15:48
  • @JacobKaif As far as I know you cannot without using this API or just plain old push notifications. – Antwan van Houdt Aug 05 '17 at 15:48
  • @JacobKaif They are basically both the same except you need to modify your apn service slightly, generate a voip push certificate and add the entitlement. I spoke to an apple representative about this and they basically don't want you using it this way. Except whatsapp, like I mentoined. They don't care about them using it that way. – Antwan van Houdt Aug 05 '17 at 15:50
  • Can you please look at [link](https://stackoverflow.com/questions/35382617/ios-notification-when-app-is-in-background) and tell me how can it help me. My messages are already in app and once app is in background i want to present a notification showing that you have a message... – Jacob Kaif Aug 05 '17 at 16:03
  • It's unclear why the answer needs voip? How does that tie in the the question about receiving and displaying *Firebase notifications* when the app is in the background? From the Firebase website: *When your app is in the background, iOS directs messages with the notification key to the system tray.* – Jay Aug 05 '17 at 16:38
  • Jay, thanks for your reply. Please elaborate a bit. I have the firebase chat ready but i have not implemented push notifications. For now what i want is that once the app is in background(due to home button press), i get notified in some manner like badge or any alert that there is a message. Is it possible? – Jacob Kaif Aug 05 '17 at 16:45
  • @JacobKaif See my comments to your question. The voIP info provided in this solution have literally nothing to do with your question about receiving notifications from Firebase so I don't know why it's an accepted answer. Firebase can send push notifications to your app, which can be received when your app is in the background. The code and instructions are provided on the Firebase website and there are multiple examples here on stackoverflow as well. – Jay Aug 06 '17 at 12:31