Running Watch Simulator and iOS Simulator - ios

When I'm running the Apple Watch simulator from Xcode, both the iOS simulator and the Watch Simulator launch but the iOS app doesn't start up. Is that by design or am I doing something wrong? I can launch either in the simulators and they communicate as expected but if both would launch at the same time that would be very useful.

Xcode doesn't have an option to automatically run both apps for you.
The existing approach is historically by design, but there are other reasons for it too. For example:
It's faster, and uses less resources to not unnecessarily (build, install and) launch the host app.
You may want to test that the watch app works as expected when it can't communicate with its paired device or app.
Within Xcode, you tell it to run a particular app, whether it be the iOS app or the watchOS app. That's the (only) app that launches.
The best you can do (within Xcode) is to first run the iOS app, then run the watchOS app. Both will be running, and you can then debug either one from within Xcode.
Of course, you could always submit a feature request to add an option to launch both apps.

Related

Understanding builds for Watch-iPhone app in XCode

I have an iPhone app with an Apple extension and when I build the app in XCode only the Watch app starts building, I see both simulators but the iPhone app doesn't launch, is this a normal behavior when testing iPhone+Watch app?
I would like to have more control as far as builds since at times I just want to test the iPhone app and the Watch app doesn't need to be involved and vice versa.
Can I have both apps launch when building in Xcode so I can debug both?
Can I stop testing the watch app and only test the iPhone app if I wanted to?
Is there a way to speedup the build time?
Thanks
If the Watch App's or Watch Extension's scheme is selected, when you press Build, only your Watch app will launch.
You can launch both separately and debug both. If you only want to test the iPhone app, you can do it exactly as usual by selecting the iPhone app and running it from Xcode.
Regarding the build time, I think it's as fast as possible. Just make sure you don't have something that causes a full rebuild each time you are debugging, as build usually takes less than 2 seconds when working on a project if the project is not building from ground up (which usually takes over a minute in a normal-sized project).

Issues running Apple Watch glance app in simulator

I'm trying to test my apple watch glance for my iOS app using the simulator, however I'm getting some very strange behaviour. When I launch the iOS app in the simulator it works without problem and the app is fully functional. However , when I then try to launch the glance app for apple watch afterwards it shows up, but the iOS app no longer works (if I try to launch it from the simulator it immediately crashes) and the data that's in the app sharing group doesn't show up on the watch (but if I relaunch the iOS app simulator from Xcode it shows up there).
I've checked both apps and they are configured for the same sharing groups and that is definitely the case.
I just don't understand why running the iOS app and the apple watch app in the simulator won't work / behave correctly together?
Credit to #WhiteTiger for this answer:
if you're using watchos 2 appgroup the system does not work on the device, you should use wcsession as the documentation indicates.
Or look at updating to use the WatchConnectivity approach instead

Debug Watch app while parent iphone application in in background

I am not able to attach watch app process into debugger while running from iPhone app.
I am following below steps.
Run iPhone app from Xcode in iPhone.
Make app in background.
Open watch app in apple watch.
Now I am doing Debug -> Attach to process. in that list apple watch process is not showing..
Any help?
I have only played with the Simulator (watch not arrived), but you better launch the watch app using Xcode and then open the iPhone app manually.
Xcode will only attach to one of them, so may need to debug one at a time.
You should run the WatchKit app target from Xcode, then launch the iPhone app manually or from Xcode. Note that you can attach to the iPhone app while attached to the WatchKit app to debug both at the same time.

WatchKit App only starts iPhone Simulator and WatchKit App, but not the IOS App

I have configured the WatchKit App to run on iPhone 6, the WatchKit App Scheme Executable points to WatchKit App.app, Watch interface points to Main, but the IOS App is not starting only the WatchKit App.
When I select the WatchKit App to run on iPhone 6, the iPhone 6 simulator is starting, I see a black screen for a second after that the simulator returns to IOS level but the main app is not starting, only the WatchKit App on the Apple Watch simulator. I can not figure out why the IOS App is not starting?
In order to debug the iOS app while running the Watch Extension, you should follow the steps explained here.
You also need to understand that the iOS App does not have to be running while the Watch app is running. You have several combinations of possible runtime scenarios...all of which your iOS app and Watch App must handle seamlessly.
iOS App is running but not the Watch App
Watch App is running but not the iOS App
Both apps are running in the foreground
Watch App is running in the foreground and iOS App is running in the background
I have also posted some additional information about launching the parent app from the Watch Extension as well as sharing data here.
Hopefully that helps.
If you want to see NSLogs from the container app, you can do this:
put a breakpoint as early in your watch app's processes as possible
run the container app
stop the container app
run the watch app and let it hit the breakpoint
with the watch app running and debugging connected, go to the simulator and open the container app by clicking on it
go back to XCode and go to Debug > Attach to process > Your container app
You should now be connected to both processes, and see breakpoints and logs from both. You can use the thread navigator in the left pane to switch between apps (which you'll need to do to get the watch app running again).
Note that an early breakpoint in the watch app is optional, I just find it useful to make sure any early breakpoints are caught.
There is a bug at the moment which hasn't been fixed yet. To get around and launch the iPhone app do the following:
1) Stop any process in Xcode.
2) Build and run the iPhone app.
3) Stop the iPhone app once launched.
4) Switch to the WatchKit scheme extension and build and run it.
5) Open your iOS app from the iPhone home screen by pressing its icon.

Can iOS app run in Xcode simulator accessing Mac hard drive location (outside sandbox)

I thought iOS app run in simulator is restricted to the simulator itself. But there is this project called iOS-Artwork-Extractor that actually accesses Mac hard drive locations outside the simulator environment. For example, it will read all apps in your itunes, etc. I am sure it uses non-public APIs.
Does that mean theoretically an iOS App running in Xcode simulator can install "unwanted" code on the Mac?
I believe that this is correct. The simulator does not enforce the sandbox the way an iOS device does, so an app running in the simulator can do anything it wants to the Mac file system.
Since you have the source code for any app you run on the simulator, you should review the code before you run it.
Only developers running Xcode can run apps in the simulator. What are you worried about, trojan horse apps for the simulator targeted at other developers?

Resources