Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a WatchKit App

I can't run a watchkit app from a new project. If I run Apple's sample project it runs fine. If I add watchkit to my existing project by adding a target for watchkit. Then run it I get a black screen with the time even though in my storyboard I have an interface controller that is set to main that has a blue background. This line of code gets called.

- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
            [self.listTable setNumberOfRows:5 withRowType:@"List"];
    NSLog(@"%@ will activate", self);
}

My main app(iPhone app) for iPhone doesn't get run on the simulator.

This is basically what I see.

Apple Watch Simulator black screen with time label in upper right corner

like image 788
user1898829 Avatar asked Nov 20 '14 06:11

user1898829


People also ask

What is a WatchKit app?

The WatchKit framework provides infrastructure for creating watchOS apps, including an extension delegate that manages background tasks, extended runtime sessions, and Siri intents. The framework also performs other support tasks, such as accessing information about the user's Apple Watch.

How do I create a watchOS app?

To build a watch-only app, start a new project in Xcode, select the Watch App template, and click Next. Provide a name, and choose the interface, life cycle, and language for your watch app. Select the options to include a notification scene template or unit and user interface tests, and click Next.

Where does the watch app extension code run in watchOS 2?

In watchOS 2, not only does the WatchKit extension run on the user's Apple Watch, it is delivered inside the user's Watch app.


2 Answers

When you run, did you change the scheme to the WatchKit App target? Or did you just build & run the iOS app as usual? For now you can't run both the iOS app target and Watch App target at the same time.

You have to switch schemes/targets as shown here, then pick the same simulator & display the watch UI as you've already done, (in the simulator -> "Hardware" tab -> External Display -> Apple Watch):

XCode screenshot of scheme dropdown

You also have to add/edit schemes to view the Glance or Notification parts of the storyboard. See the "Readme" file in the sample Lister project for more details.

like image 76
mc01 Avatar answered Sep 21 '22 04:09

mc01


I had a similar issue. Here is a couple of things you can try (solved it for me)

  • make sure you app, watchkitapp and watchkitextension have the same bundle id e.g. com.company.app for the app and com.company.app.watchapp for the watchkit app. I have several build configs with different bundle ids, so xcode took the wrong one during watch target creation. You'll get a compiler error if app's and extension's are different, but watchapp bundle id will not create an error.
  • first run of the app, before you open the watch in the external devices menu will hit all the breakpoints and logs but you'll see nothing after you open the watch simulator.
  • a couple of times the app got stuck on launch for me - in debug navigator the state was 'waiting to attach'. had to reset the simulator every time after that.

Hope it helps.

like image 24
Max Mikheyenko Avatar answered Sep 21 '22 04:09

Max Mikheyenko