简体   繁体   中英

WCSession in iOS App using WatchKit 2 Stops App Building

I'm trying to setup communication between my Watch App and my iPhone App using the new WCSession stuff in iOS 9.

Everything went smoothly adding the WCSession to the watch extension but once I try to add the same thing into my phone target the app will no longer build and gives me this error.

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_WCSession", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm importing it with this:

#import <WatchConnectivity/WatchConnectivity.h>

and then trying to call:

if ([WCSession isSupported])
{
    self.session = [WCSession defaultSession];
    self.session.delegate = self;
    [self.session activateSession];
}

There aren't any errors showing up in the Xcode editor. It just won't build. I'm trying to run it on the simulator.

Any ideas?

Have you added a reference to the WatchConnectivity.framework to your iOS project? It needs to be referenced in both the iOS and watchOS projects.

Add "WatchConnectivity.framework" using "Link Binary With Libraries" in "Build Phases" in ios app.

Make sure that you have imported #import <WatchConnectivity/WatchConnectivity.h> in ios app and watch app. Also view controller in ios app and InterfaceController in watch app conforms to <WCSessionDelegate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM