How to show notification in iWatch? - ios

In my app, I want to implement functionality like when iPhone away with some distance from iWatch than watch app show local notification with a text message

If it is enough for you to get notified when the Watch gets disconnected from the Phone, you could use the WatchConnectivity framework to achieve this.
The optional func sessionReachabilityDidChange(_:) gets called on the Watch when it disconnects from the Phone.
However, your WatchExtension needs to be running in the foreground or with high priority in the background for this function to work.

Related

swift: How to make a call when phone is locked or app in background

I have implemented Agora call in iOS app which works perfectly fine when app is in foreground ... Actually in my case we initiate call through Bluetooth BLE iBeacon. Along with this we call an API which is also working fine.
Problem is when app in background or when phone is locked ... Even when app is in background, app listens bluetooth event and Call API but it never start Agora call until we bring app to foreground. Means call works in foreground or it waits to start call when app enter in foreground.
To handle this I implemented local notification to prompt user to tap notification and bring app to foreground. But we want to do it through Bluetooth iBeacon. That instead of user to tap notification, it press beacon button to bring app in foreground and start call. On beacon button press I can catch the event in background as well but unable to bring the app to foreground.
Could not find some solution of it. But seems like its do-able as with Car tablets which are connected with bluetooth to phone we can dial a number on tablet and through bluetooth communication with phone it makes a call to selected or dial number even when phone is locked.
Means third party bluetooth devices can send command to locked phone and initiate call.
There are two ways using that you can make calls when app is in background or in locked state even your app is in killed state.
Using CallKit Framework provided by apple.
You can send custom push notification to the user and on click of push notification application is wake up and call is happen.

How can I detect lockscreen status to choose between CallKit and LocalNotification for incoming calls?

How to detect phone lockscreen status in a PushKit delegate to choose between notifying the Call to CallKit or using a LocalNotification to notify the user. The aim is to avoid having users actually have to Tap the video button when answering from lockscreen (Because more often then not, test users can't figure it out and get frustrated).
We have a Chat application written in Xamarin that supports audio/video calls over WebRTC.
On iOS incoming calls when the app is in the background or closed are handled using PushKit.
We also implemented CallKit looking to get a more native feel.
But when we receive a call on a locked screen iOS device, after answering CallKit UI stays on top, and we can only move to video call if the user taps the button.
The fact is that CallKit UI answering behavior is inconsistent between Foreground, Background and Locked states, and our users usually can't figure out why they are not getting the App Call UI after answering on locked screen.
We noticed that WhatsApp has worked around the problem by reverting to a visible notification when the screen is locked, and only seems to use CallKit when unlocked, but we can't figure out how to replicate this behavior.
How can we reliably detect Phone lock screen status in our PushKit delegate?
We have tried monitoring screen brightness, but it always gives the same value regardless of state.

How to come Ios App to foreground from background

I working on swift for Ios App. I want to phone user connect specific wifi. So i open iphone wifi settings by NSURL like this. After then my app go to background and i control ssid every 500ms in background by background task like this. When phone connect the specific wifi i can see this status and i stop background task. But i cant comes my app to foreground. I tried open my app use NSURL metod like this video (i add custom url my info.plist and add application function in my appdelagate) but my app has no return use this metod.
unfortunately bringing an app from background to foreground is not possible. You can however send a notification or a badge for the user to click and open the app. The user should have notifications enabled for this to work.
Happy Coding!

ios play continues sound when app receive push notification

Currently i am working on app in which i want to play continues sound when app receives push notification. as i know apple allow to play custom sound of length of 30 sec here is link..
but in well known app it plays continues sound in driver side when app is in back ground and driver receives order.
and another issue is of when my app is in back ground and receives push notification Rather clicking on notification if i open app by pressing app icon it does not show me data of push. it is not possible to load data when press on app icon here is link
iOS Push notification issue
but same thing is done in well known app
With iOS 7+, use application:didReceiveRemoteNotification:fetchCompletionHandler:, which is called even if your app is in the background. iOS will even launch your app in the background if it's not already running, but if the user force quits the app, it will not be re-launched. If you enable the remote-notification background mode, you can run app code when the notification arrives. If you include the audio background mode, you could initiate a sound that continues to play while app is in background.
For second question, typically, your app should query a server for updates if it's launched directly. However, you could leverage a remote notification as above, which you'd get in most cases (except if the app were force quit).

How to bring application to foreground in ios?

I am detecting for iBeacon in background. When my device comes in a particular region application should comes to foreground.
It cannot be done without user interaction. The only option is you can generate a push notification to tell the user to bring the application to foreground.
This is from the Apple documentation about this issue:
When the operating system delivers push notification (iOS or OS X)
and the target application is not running in the foreground, it
presents the notification (alert, icon badge number, sound). If there
is a notification alert and the user taps or clicks the action button
(or moves the action slider), the application launches and calls a
method to pass in the local-notification object or remote-notification
payload. If the application is running in the foreground when the
notification is delivered, the application delegate receives a local
or push notification.
To answer to some comments about WhatsApp, with it, when you receive a classic vocal call, IOS use CallKit to display your call and wake up your phone, but it's not inside app. I try to make a video call with WhatsApp, and in this case, there is a notification. Press notification open app and answer to the call.
Conclusion : It's impossible to wake up app from background to foreground in IOS, but it's not really a problem because you can use notification to display what you want and get the user to your app after a touch on your notification. All of iPhone users are familiar with this kind of interaction, it's better to deal with it.

Resources