Can I keep my WatchKit App running in the background on the Apple Watch? - ios

I want to know if there is anyway to keep my WatchKit app running in the background, or if I can possibly program it to launch (i.e. transfer from inactive state to active state) once a certain condition is fulfilled?
My app is running perfectly while the WK App is open and active, and it even runs fine when the iPhone is asleep, or when the parent iOS app is in BG mode. However, I really need my app to continue running in the background on the watch itself. Is this possible?

Not possible. Because Apple Document for watchkit clearly mentions that "WatchKit extensions do not support background execution modes,they run only while the user is interacting with the corresponding app on Apple Watch.".
You can refer apple document Link to Apple Doc
Read Communicating Directly with Your Containing iOS App.

Related

Trigger apple watch application launch from iPhone [duplicate]

I would like to give a hint to the user, that my iOS app supports the Apple Watch.
So I would like to link/open the Apple Watch companion app from within my iOS app, very much similar to opening the Settings App using ([[UIApplication sharedApplication] openURL: [NSURL URLWithString:UIApplicationOpenSettingsURLString]];)
This shall enable the user to directly navigate to the Watch companion app to setup my app for the watch.
I could not find any URL which would open the companion app in general or specific to a section of the companion app.
If direct linking is not supported, I am also interested in alternative approaches for this use case.
Thanks in advance!
EDIT:
I checked the WatchKitSettings Info.plist file in the simulator to see if it registers any URL schema, but it does not.
I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.
You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.
Previously, it was not possible to launch the WatchKit App from the iPhone app, but the iPhone app could be launched—only in the background—with the openParentApplication method.
As of WatchOS 2, however, it is now not possible for either app to cause the other to launch. Instead, there are new methods for queueing changes to be picked up when the other app is launched in the future.
One partial solution for your use case could be displaying a local notification which could be tapped to open the watch app. The primary flaw in such an approach is I do not believe there is a way to limit this notification to the Watch only, so it would also appear on the iPhone where if tapped it would bring the iPhone app to the foreground. Messy if implemented like this, and therefore not worth it I'd have thought, even if it could pass app store review.

How to programmatically open Apple Watch companion app from iOS app

I would like to give a hint to the user, that my iOS app supports the Apple Watch.
So I would like to link/open the Apple Watch companion app from within my iOS app, very much similar to opening the Settings App using ([[UIApplication sharedApplication] openURL: [NSURL URLWithString:UIApplicationOpenSettingsURLString]];)
This shall enable the user to directly navigate to the Watch companion app to setup my app for the watch.
I could not find any URL which would open the companion app in general or specific to a section of the companion app.
If direct linking is not supported, I am also interested in alternative approaches for this use case.
Thanks in advance!
EDIT:
I checked the WatchKitSettings Info.plist file in the simulator to see if it registers any URL schema, but it does not.
I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.
You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.
Previously, it was not possible to launch the WatchKit App from the iPhone app, but the iPhone app could be launched—only in the background—with the openParentApplication method.
As of WatchOS 2, however, it is now not possible for either app to cause the other to launch. Instead, there are new methods for queueing changes to be picked up when the other app is launched in the future.
One partial solution for your use case could be displaying a local notification which could be tapped to open the watch app. The primary flaw in such an approach is I do not believe there is a way to limit this notification to the Watch only, so it would also appear on the iPhone where if tapped it would bring the iPhone app to the foreground. Messy if implemented like this, and therefore not worth it I'd have thought, even if it could pass app store review.

Apple Watch : will the App on iPhone run in the background

Am trying a simple Apple Watch App. the question I have is : will the iPhone App be able to run always in the background? In the App, I want to fetch some files from a server & store them in the iPhone (I want to do this everyday at a specific time), so that when the user opens the Apple Watch App, the file can be showed immediately (and no need to wait for it be downloaded then).
You can run tasks in the background of an iPhone application yes. I have no idea about how this interacts with the Apple Watch (your post suggests this will just sync automatically perhaps). Good point of reading:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

Application does not work properly in background without Xcode

I'm building an activity analyzer application for iPhone and I use iOS 7. In order to do these i use CMMotionManager and I access accelerometer data.After this I write the datum to database. My application has to work also in background and I used queues, GCD, blocks and other such things in my code to do this properly. Problem is, all of these are working properly when iPhone is plugged in with Xcode but if I run the app without Xcode, app runs about 4 or 5 minutes.After, it is terminated.What is the reason for this?
iOS apps can only run in background, if they fit in one of apples defined background modes such as "App registers for location updates","App provides Voice over IP services","App plays audio","App processes Newsstand Kit downloads","App communicates using CoreBluetooth"",App shares data using CoreBluetooth" and a few more. All background modes you will find in xcode in the capabilities section auf your project(click on project name upper left->mainwindow->second tab).
if your app fits into one of these modes, you must enable this in your app.plist by setting the checkbox in the capabilities section.
if your app doesn't fit in any of these modes you can run in background only a limited amount of time and then iOS stops all activities.
For testing you could start any background mode. but when your app shall be reviewed for deploying via app store apple will reject the app if you use the background mode without legitimation.
The reason for this is that iOS 7 (actually all versions of iOS) will suspend a background task, and potentially terminate it if it's misbehaving, only certain kinds of apps can keep running. Here is the apple doc on it: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
So, given your situation, you'd most likely have to "lie" about what type of app your app actually is, which will get you rejected from the app store.
If you do decide to go the route of a hack, be very careful about battery life, cpu usage, and memory usage, as there is a reason apple did this.
FYI: The "type" is set in your Info.plist file.

Enable download in background with phonegap ios app

I am using phonegap 2.2.0 to develop an ios app. The app requires to download some videos which i'm doing with the FileTransfer. The problem is if the app goes background i.e if the screen is locked or if the home key is pressed, download gets cancelled. I need to continue downloading the videos even when the app is in background. Is there any workaround for this?
The problem is that your app gets suspended after a short period of being in background mode, so it is no longer executing code. You need to either declare and implement your app as a service (UIBackgroundModes in Info.plist), or delay the suspension (in applicationDidEnterBackground handler). Both cases are tricky if you are a pure PhoneGap developer.
I wrote a small PhoneGap plugin for iOS that checks whether the app has called for background mode, and if so prevents it from getting suspended (normally up to 10 minutes) until the mode is revoked.
See this article for more detail.

Resources