Equivalents for UIDevice on Apple Watch?

My WatchKit 1.0 app, used UIDevice to pass the status of the iPhone to the Apple Watch and

worked well. Now though, with xCode 7 and WatchKit 2 UIDevice is no longer available. Is there

an alternative or do I need to completely rethink my Watch App?

Replies

Unfortunately you cannot directly access to UIDevice.

I think you should use Watch Connectivity Framework to get updates of the status of the iPhone.

In particular, sendMessage can wake up your iOS app in background and receive live replies:

- (void) sendMessage:(NSDictionary *)applicationData {
    WCSession *session = [WCSession defaultSession];
    if ([session isReachable]) {
        [session sendMessage:applicationData
                replyHandler:^(NSDictionary *reply) {
                   // just received status update
                }
                errorHandler:^(NSError *error) {
                    NSLog(@"ERROR: %@", error.localizedDescription);
                }
         ];
    }
}


- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * _Nonnull))replyHandler {
     // get iPhone status
     UIDevice *myDevice = [UIDevice currentDevice];
     
     // send status as reply
     NSDictionary *replyDict = [NSDictionary dictionary];
     replyHandler(replyDict);
}
WKInterfaceDevice could be helpful - https://developer.apple.com/documentation/watchkit/wkinterfacedevice