i wonder if the following scenario is possible:
is it possible to use web-sockets (e.g. socket.io) to implement a kind of push notification? i think about the following method: when i save a web-app to the homescreen, open it and close it (so it's in the background), i send a notification over a server and the web-app in the background displays a alert-view?
thanks advance
Backgrounded app are not running. They will drop the connection after a few seconds.
The native notification system hands off the job of handling receiving notifications and restarting the app to the OS.
So you register to receive them with the OS and when one arrives to the device the OS will start your app and pass on the notification.
You'd need a PhoneGap native wrapper to achieve this for your web app.
Example
Related
Recently Apple changed its way of handling VoIP notifications. Now they force you to use CallKit in the same run loop in order not to throw your notification away. The trace I get is this one
Apps receving VoIP pushes must post an incoming call (via CallKit or IncomingCallNotifications) in the same run loop as pushRegistry:didReceiveIncomingPushWithPayload:forType:[withCompletionHandler:] without delay.
When you get this warning three times, the system is "dropping your notifications on the floor".
The problem here is that I'm developing a hybrid VoIP app using the phonegap-plugin-push, and I'm afraid that the on notification event is not fast enough (or at least not the same run loop) for iOS.
Did anyone face this issue?
I've thought of changing to regular push notifications, but I can't find a way to make my app relaunch when it's killed and execute some code (launch CallKit, for example).
Edit:
I'm trying this approach with push notifications and I already configured the background modes. I noticed that sending the "content-available" and some data, like "badge", or "alert" in the notification, the app is launched if it went to background recently. After 15 minutes in the background the push notification arrives but the app doesn't launch anymore
Thank you in advance.
Our app uses CallKit and push notifications, and it launches when a push notification arrives for a new incoming call. It has to be configured in the project build and run once to register with iOS for this, though.
I found a solution:
Since iOS changed its policy about handling voip push notifications, it forces you to report a new incoming call when receiving the voip: https://forums.developer.apple.com/thread/117939
This plugin does it: https://github.com/mattkhaw/cordova-plugin-callkit
It merges two plugins (WebsiteBeaver/CordovaCall and Hitman666/cordova-ios-voip-push). It worked for me. I just had to remove the receiveCall from the javascript and tweak a little bit the plugin.
The methods related to the voip notifications register are in the cordovaCall class, so it is pretty straightforward to work with.
I am using react-native-notification module to send a local notification when I receive a socket.io event sent from the server. The notification is properly configured and works on both iOS and Android in foreground mode. However, due to the fact that Apple doesn't allow Apps to run on the background except for (Audio, navigation map, etc.), I am not able to receive any socket events when my app is not on the background and temporarily suspended.
I'm therefore not able to send a local notification to the iOS device since the app isn't really running once I switch the app to background.
Here I'm asking for possible solutions to my current problem.
This could be a general question regarding react native or iOS native.
Everything works well on Android devices and I don't think there is anything wrong with my code so I don't know what code I should display here.
In short, I just want to know how to receive socket events when the app is in the background on an iOS device, or if that can't be achieved. I would like to know how most apps even send notifications to their users when their apps are in the background.(I do not want to cheat the system and set the background mode to audio).
I know its a old post but if anyone still wondering, You can send notification even your app is closed or socket disconnected. You can use firebase push notification which will handle your current situation even if your app is killed.
Try below plugin to send notification to both android/ios without using any background service react-native-firebase
BACKGROUND
I am buidling a chat messaging applicaiton and I faced a problem handling push notificaton when user receiving message from the sender.
WHAT I WANT TO ACHIEVE
Like Whatsapp does, after I received the push notification and I turned on the airplane mode, I still can see the message contents while I open the app. so, I believe it has gotten the message while receiving the notification.
PROBLEM
I cannot find a good way to handle the remote chat message push notification when the user opens the app through its icon on the home screen instead of pressing or doing another action on the notification.
WHAT I TRIED
I manually loaded the message when the app did apear, but this is not like the tested behavior on Whatsapp.
I tried this third party socket library, but iOS killed the listening service once the app was closed, it is not applicable to what I want to build.
MY QUESTION
If still using the push notification or background mode remote notification, is that any way to able to handle the push notification when the app is not running?
I also find out about the Apple PushKit, I not sure if this is only allowed for VoIP providing apps. Does anyone know if Apple will accept my app to be published to their AppStore if I use the PushKit for only text messaging?
The untimate question, how can Whatsapp achieve this? Does it use PushKit as well?
Actually you can't handle something when your app is killed, so simple solution for you problem is to store all push notifications data in server , get it from server when you run app, and delete them once you got them. I think Whatsapp handle this in same way.
Just search about XMPP server, for live chat there is no need for Pushkit, Pushkit is only for Video call notification when app is terminated.
Use XMPP server for live chat integration.
https://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-setup--mobile-7190
What is XMPP, and how can I use it within an iOS chat application?
How does Whatsapp continue to receive notifications of received messages, even after you kill the app or restart the phone?
I am using an application that sends location coordinates, and it's for iOS, written in Swift.
My problem is that when I kill the app, the application stops sending coordinates. How I can make it restart automatically? For example, Whastapp, despite killing the app, if someone sends me a message, I receive the notification
I have also tried creating a widget app, but this is activated only when under the bar where the widget exists.
WhatsApp continues receiving PushNotifications. These are sent by Web Server and the App need not be active for it.
Coming to your requirement, you can use options like requestAlwaysAuthorization (to keep App awake in background to be able to send notifications). SignificantLocationChange, RegionMonitoringService, VisitService (to relaunch you app in the background if terminated).
Hope it helps.
Use this tutorial https://www.raywenderlich.com/123862/push-notifications-tutorial. you need to have one developer account to use push notification. It's easy to implement.
is it possible to have the App Connection to a server Open even if the App has been Terminated from the Background ?
Here is what I'm trying to accomplish
Twitter Client should keep watching user events . and when that events occur it send a Local notification to the user . the whole idea is to stay a way from Push notification and all servers Problems and costs
so in order to to get Local notification works just like Push notification the connection between my IOS 7 App and Twitter API must be Open all the time
any idea if that even possible ?
No, this is not possible. What you're basically asking for is a daemon functionality which is not available on iOS. The whole point about iOS multitasking is that the OS can (and will) terminate your app if it is in the background and other tasks need the resources. That's the problem Push Notifications solve (to some degree).
You could possibly try background fetch feature on iOS 7 to periodically download content updates for user in background.