I have a device, located in a Wi-Fi local network possibly without Internet connection, which sends notifications to the devices that are connected to it using a web-socket.
But when I lock the phone or press the home button, my application goes to background mode and the web-socket connection gets closed, so since then any notification doesn't get to the phone.
I know I can do this by using remote notifications (with Apple Push Notification Service), but my device is intended to work on any Wi-Fi network (with or without Internet access) or generating its own Wi-Fi access point (and therefore without Internet access).
So the question is: Is it possible to have a persistent connection, like in Android where I can maintain a connection in a background service?
No, you can't if you want your app in the App Store.
If not (for example this is an Enterprise app), you can use kind of hacks, like silent audio or voip but this will drain battery a lot.
In iOS, only specific app types are allowed to run in the background:
Apps that play audible content to the user while in the background, such as a music player app
Apps that record audio content while in the background
Apps that keep users informed of their location at all times, such as a navigation app
Apps that support Voice over Internet Protocol (VoIP).
Apps that need to download and process new content regularly
Apps that receive regular updates from external accessories
unlimited backgrounding on ios with silent audio
Apple docs - background execution
Related
I have an iOS app that plays music with the MusicKit API. I want to write a companion app for macOS that communicates with the iOS app.
For example, my iPhone is playing music. When a new track starts playing, a notification appears in the macOS app. I can click a button on macOS to skip to the next track on my phone.
What's the best way to communicate between devices like this?
I think there are two important use cases:
For static data like account details and preferences.
For real-time messages.
I could do everything via a remote server but I wonder if there's a better way.
The user needs to have your app installed on iOS and macOS and needs to separately grant permission to receive push notifications.
Keep in mind that Apple does not guarantee the real-time delivery or delivery at all of remote push notifications. Remote push notifications may also be discarded by the APNS if many are sent within a short timeframe. It is not recommended to use the APNS for user-initiated actions such as music track controlling, as the user expects an (immediate) result. A web socket or other permanent connection between your server and its clients should be used instead.
Playing music on one device, stopping on another:
Request permission to send remote push notifications to get the unique APNS token for each device.
Store the device tokens on your server.
Make the iOS client notify the server that the user started playing music.
Make the server send a remote push notification to the macOS client via the APNS.
On the macOS client handle the user interaction with the push notification and report the user action back to the server.
Make the server notify the iOS of the user interaction via a web socket connection, rather than a remote push notification to ensure that the client handles the user action.
Make the iOS client skip the track.
Synching user preferences:
Store preferences on server for every change.
Request preferences from server on every app launch or dynamically when the preferences change by triggering the request through a remote push notification by the server or via a web socket connection, depending on how real-time the synchronization should be.
I want to sync my local DB with server when Push notification came, but I am not able to do it with Silent Notification because application:didReceiveRemoteNotification:fetchCompletionHandler not called when app killed by user. So, I did not know how to do it, then I read about push kit but don't know is it possible to use push kit without VoiP feature. Please tell me is it possible or not??
If not, suggest me any other idea , how will I run background task when app killed by user??
In my experience as well as others on SO - you get rejected for trying to leverage VOIP as a workaround. See below for actual response from apple dealing with a similar attempt.
2.16: Multitasking apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc.
2.16 We found that your app uses a background mode but does not include functionality that requires that mode to run persistently. This behavior is not in compliance with the App Store Review Guidelines.
We noticed your app declares support for VoIP in the UIBackgroundModes key in your Info.plist but does not provide any Voice over IP services.
We recognize that VoIP can provide "keep alive" functionality that many app features would like to use. However, using VoIP in this manner is not the intended purpose of VoIP, which, as indicated in the iOS Application Programming Guide, is that: "A Voice over Internet Protocol (VoIP) application allows the user to make phone calls using an Internet connection instead of the device's cellular service."
Seems that the only way to restart the app when it was killed by user is to use PushKit.
It is possible to use PK framework in your app without Voip functionality, but I can't guarantee you, that your app will not be banned while posting to AppStore.
I am trying to develop an iOS app that delivers time critical alerts to staff when certain events occur (handled by a server on the clients site, on the client network). This notification needs to be delivered to the iOS device even when the internet is down (since the alert is time critical it cannot wait for internet to come back up), some client's site do lose internet access often enough for this to be an issue. I don't believe that this is achievable via iOS Push Notification since it requires connection to internet. And the issue with local notification is if the device is asleep for some reason they will not get the alert, unless I have an infinite background operation running. Now battery life on devices is not an issue as they will be rotating multiple devices, so if one dies they can log into another iTouch, and charge the old one. The issue I see is that you cannot have an infinite background task running (to deliver the local notifications) and have it in the app store without some sort of VOIP service also added, and this would be given to our clients so it doesn't really fall under the enterprise license. I have email Apple dev support with this question and have not received any response. Does anyone have any idea the best way to achieve this time sensitive notification (without internet access) with an iOS device?
I heard about iOS it self wouldn't allow an app to stay longer while its in background. I don't know exact minutes but how I can active my app to handle video / audio calls or for chat functionality. I'm using Quickblox iOS SDK for video/audio calls and chatting.
P.S. I've successfully implemented this functionality only worry about background? Is there a way in Quickblox SDK to achieve this?
Any help/suggestions would be highly appreciated.
Here is the list of the application where you can perform actions or keep alive your app while your app is in background.
Audio and AirPlay
The app plays audible content to the user or records audio while in the background. (This content includes streaming audio or video content using AirPlay.)
The user must grant permission for apps to use the microphone prior to the first use; for more information, see Supporting User Privacy.
Location updates
The app keeps users informed of their location, even while it is running in the background.
Voice over IP
The app provides the ability for the user to make phone calls using an Internet connection
Newsstand downloads
The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.
External accessory communication
The app works with a hardware accessory that needs to deliver updates on a regular schedule through the External Accessory framework.
Uses Bluetooth LE accessories
The app works with a Bluetooth accessory that needs to deliver updates on a regular schedule through the Core Bluetooth framework.
Acts as a Bluetooth LE accessory
The app supports Bluetooth communication in peripheral mode through the Core Bluetooth framework.
Using this mode requires user authorization; for more information, see Supporting User Privacy.
Background fetch
The app regularly downloads and processes small amounts of content from the network.
Remote notifications
The app wants to start downloading content when a push notification arrives. Use this notification to minimize the delay in showing content related to the push notification.
If your app will be performing one of the above tasks just add related key into your plist file. For more check official Apple docs: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Quick question, I am working on an APNS enabled app and I just want to know if there is a way that when the app is not open (not in background) and the app receives a remote notification;
Can I open the app in the background, unbeknownst to the the user, and do do what needs to be done.
I have looked at the docs but it doesnt explicitly say that this can or cannot be done (from what I read), it says that the user has to open the app manually (either from tapping an alert or the app icon).
I think it is clear what I'm looking to do however i'll put an example aswell.
Example)
The default Mail app alerts the user of new emails with a badge icon, showing the number of new emails, aswell as a sound. The user must then tap the app icon to open the app and download the new emails.
I want to be able to have the badge and sound but open the app in the background (silently) and download the new emails, so that when the user does get around to opening the app the emails will already be there, ready to read.
Thanks for any help.
unfortunately, what you describe is not possible.
the only way you could get something like that is to build a voip app. see the relevant section in this document.
Implementing a VoIP Application
A Voice over Internet Protocol (VoIP) application allows the user to make phone calls using an Internet connection instead of the device’s cellular service. Such an application needs to maintain a persistent network connection to its associated service so that it can receive incoming calls and other relevant data. Rather than keep VoIP applications awake all the time, the system allows them to be suspended and provides facilities for monitoring their sockets for them. When incoming traffic is detected, the system wakes up the VoIP application and returns control of its sockets to it.
anyway, I doubt that your app would get into the App Store, then...