How to keep app running on apple watch instead of automatically going back to watch face? - ios

I'm developing a WatchKit app that I want to stay in focus until the user actively selects another app or goes back to the watch using the digital crown. Just like with the built-in Workout app.
I don't want the app to be visible on screen forever, just that when I look at the watch after some minutes I want to have updated information for my app without having to go back to the app manually due to automatic switch to the watch face.

I don't think you can control this in your app, at least not in WatchOS 1. The only way I think this can be done is for the user to select "Resume To: Last Used App" in Settings > Activate on Wrist Raise.
Apps such as Nike+ currently advise users to change this setting before starting a run.
WatchOS 2 allows apps to register as fitness apps, that will contribute as a workout and will resume when the watch is activated / raised.

Related

How do I prevent Interface Controller from locking screen? (WatchOS)

I'm trying to make a specific Interface Controller (on my independent Watch App) not go idle.
I've tried this, but ran into the issue that an independent Watch App cannot support UIKit. I've been trying to find a work-around, but haven't found anything yet.
Here's the code I'm trying to get to work:
UIApplication.shared.isIdleTimerDisabled = true
No watch app, independent or otherwise, can use UIKit. watchOS apps use WatchKit.
There is no direct equivalent to isIdleTimerDisabled due to the more limited battery life of watches.
If your app is a "self care" or "mindfulness" app then you can use an extended runtime session to remain as the front most app for 10 minutes or 1 hour.
If it is a fitness app then you can use an HKWorkoutSession to be the default front most app when the user raises their wrist during the workout.

How to launch an associated watch app from an IOS application

How do I launch an associated Watch App from an IOS App?
I do see questions where the user flow is in reverse, where the Watch App starts the IOS App in the background. However I want the reverse. I want to launch the Watch App, make it visible on the watch when the associated IOS App is running.
My current user experience is not good; I launch the IOS App from the Phone, then fiddle with the watch to find the associated Watch App.
The current IOS App plays music at times, and I have added the Now Playing View. I have also noticed that when I start the watch application "not programatically", some minutes later (after the watch goes to sleep and raised again to awake) the default music player Watch App is made the current watch application when playing music via the IOS App.
I would have preferred that the associated watch application is active on the watch, and that the Now Playing View controls the music.
The watch application has two views/pages where the user would swipe to move to the next page. The first page has some text and the second page has the Now Playing View
It would be far better, if the users starts the IOS App and auto launches the associated Watch App.
I am not sure what the design decisions are regarding this. Perhaps a Notification needs to be sent, and the user can then decide whether to launch the Watch App.
Please assist by giving brief API calls to make or adjusting properties in the plist.
Thanks.
You can do so by sending a workout configuration to your watch app via
startWatchAppWithWorkoutConfiguration
I'm not sure it would get past the App Review for non workout apps. You might have to call this method twice to reliably start the app, due to a timeout: forum discussion

iOS/Xcode: is there a difference between running the App on an iPhone while connected to Xcode compared to opening the installed App afterwards?

I have a Timer which plays AVAudio at a specific time while the screen is locked (app in foreground when locked and plist setting 'Application does not run in background' set to YES).
When I run my code while my iPhone is connected to Xcode it works as desired, playing audio while locked even when the iPhone has been locked for hours.
Now if I disconnect my iPhone and just open the app by tapping the icon the audio won't be played if it's set for more than a minute.
Is there a difference that causes this problem? If I would publish my App to the AppStore which behaviour would my users get?
That 'Application does not run in background' flag is a very old flag that means your app does not support multitasking and should be terminated when the user presses the home button. There's no good reason I can think of to set that flag on a newly developed application. Unless you understand exactly what it's for and are positive that setting it to yes is the correct thing to do, don't do that.
(That flag was added when iOS 4 was released, to allow apps that could not handle multi-tasking to request the old terminate-on-home-button behavior from iOS 3. Given that we're now 6 major iOS releases from iOS 4, it seems outdated.)
So remove that flag. It probably doesn't have any impact on your question, but remove it or set it to no in any case.
If you want to run a timer while the phone is locked and play sounds at designated times then you will probably need to set your app up as a background sound player, and ask for more background time when you get a message that you are going to the background.
That being said it's likely that Apple will reject your app. Running a timer from the background means that the processor on the phone has to run at full speed all the time, which will DRAMATICALLY reduce battery life.
Apple only allows a very small subset of apps to run in the background, and then only under specific circumstances (like a background sound playing app when the user is actively listening to music, or a navigation app that is actively tracking the user's location and notifying them when it's time to make a turn to follow directions.)
Should be no different. If you'd like to feel what do your users' feel then you can publish it to TestFlight which is the best app beta test environment. Find some testers or try it yourself.
The directions should be to verify the playing logic and the sound file relationship which link to the connection.

iOS Watchkit: Is it possible to show static UI in Watch when app is not reachable?

Can we show some static UI in the watch when iPhone is not reachable to AppleWatch?
Suppose I forgot my iPhone at car seat , and when I move from car, Is it possible to shows some static UI in AppleWatch that you forgot your iPhone?
From an Apple evangelist on https://devforums.apple.com/thread/254576?tstart=0
The end result is that if iPhone is unreachable, the app will not
function. There is not a way to currently cache information to keep it
alive or seemingly so.
Actually you don't have to do anything. I noticed on the real Watch, that Apple will present a default "iPhone unavailable" screen in case the iPhone is out of reach. Similarly, Apple will also present a default "flight mode" screen when the Watch is in flight mode :) . See attached screenshots.
In WatchOS 2, it is now possible to have a WatchKit App that runs on the Watch when the iPhone is not accessible.
Previous answer:
It is clear from Apple's public statements and the WatchKit API that third party developers do not need to manage the connectivity between the watch and the phone, and indeed cannot even if they want to.
Given Apple have publicly indicated that Watch app interactions are expected to be measured in seconds, not minutes, and that developers need to assume that their Watch app could be quit at any time (and the associated WatchKit extension) it seems highly likely that there will not be any option to present static content in the event of the phone being unreachable—as the Watch OS will immediately take over the process of interacting with the user.
It seems almost certain that this will change later in 2015, given developers have been told there will be an SDK to develop 'fully native' apps at that time.
Technically speaking you could start off the app storyboard scene with static content. if the phone is unreachable, then this scene will be displayed. But as soon as your app, whether programmatically or by user interaction attempts to use anything from the WatchKit Extension, a spinner will appear.

Lock iOS app in single app mode programmatically

Note : I don't want to submit this app to app store.
What i want to achieve :
I want simple app with one view having two button Lock and Unlock.
Lock - This button will lock device. Only this app's screen will show nothing else will be accessible even after restart same screen will show up. Home button, gestures will get disabled similar to single app mode.
Unlock - This will unlock device and switch to normal behaviour of device.
iOS :
I want this for iOS 4.3 and above.
I have checked following solutions, but these don't match my requirements
Configuration profile
Lock-down iPhone/iPod/iPad so it can only run one app
But it is manual (reboot device, open app which you want to run in single app mode). I want to do it programmatically the way i mentioned above through my app.
Guided access (iOS 6 and above)
How to lock down user to Single App mode in iOS 6, Programmatically?
I want it do for all os and programatically.
Is there any way to do this ? As i don't wan't to submit it to app store is there any private api, some hack for springboard to achieve this ?
Thanks in advance !!
As I know in iOS 7 there is a new feature which allow to do exactly what you want.
However, it's only applicable for iOS 7 (and I believe it's only applicable to a supervised devices).
1) You will need to install restriction configuration profile with autonomousSingleAppModePermittedAppIDs key (take a look here)
This is one time step and a user will need to manually accept this configuration profile.
There is another option to use MDM to install it silently, but it could be an overkill for you.
2) You should use API:
UIAccessibilityRequestGuidedAccessSession (to lock/unlock)
It is defined here
3) And most beautility part. All of it is officially document. So, you can even submit it to AppStore.
P.S. Why do you care about 4.3 or 5? They have tiny market share by now. Most likely even iOS 6 has below 20% market share already.
Update 1
Potentially, you can try to use API which sends clicks and keys (search for GSEvent in iPhone-privateapi tag). May be using these API's you can do triple home to toggle accessibility on and off.
If this work, I think you should be able to cover iOS 6. I am not sure whether both this API and triple home click were available prior that.
It looks like this private API is unaccessible anymore in iOS 7. So, probably you can ignore this idea.
Just wanted to write on this even though this is old as i needed to implement a similar solution and i got it working. The steps for me as follows and a note here is that this involves MDM and other specific steps.
My requirement was as follows. Each of the iPad at different locations has a set of apps installed.For ease of it lets assume each Dept. has their own apps. Participants open a app related to their dept. to take a test, the APP automatically Locks the iPad to single-app Mode and at the end of the test, it will unlock it self.
Supervise the iPad/iphone using the Apple Configurator.
Install the MDM related files ( Each MDM has its own set of instructions, usually involves downloading a profile).
Every MDM has a option of Single APP Mode or MultipleAppMode. Select the second option and add the app IDs to the list. (A single APP mode works pretty well with MDM's but i did not want the app to be locked to a single APP all the time).
I used the UIAccessibilityRequestGuidedAccessSession api to lock unlock the device from single app mode.
http://bobxcode.blogspot.com/2015/12/programmatically-implement-single-app.html
Thanks,
Bob
In MDM configuration, There is an option
autonomousSingleAppModePermittedAppIDs
Optional. Supervised only. If present, allows apps
identified by the bundle IDs listed in the array to
autonomously enter Single App Mode.
Availability: Available only in iOS 7.0 and later.
But this needs Supervised Device mode.

Resources