Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
916 views
in Technique[技术] by (71.8m points)

objective c - Calling a Method on Watchkit

I attended to a watchkit hackathon yesterday and I had some problems regarding calling a method on an NSObject class which uses the Google Maps API and send local notifications. If I call this method from my Watchkit extension, the code doesn't compile, but If I call from the ViewController, for example, everything works perfectly

#import "InterfaceController.h"
#import "Methods.h"

@interface InterfaceController()

 @end


 @implementation InterfaceController

- (instancetype)initWithContext:(id)context {
self = [super initWithContext:context];
if (self){
    // Initialize variables here.
    // Configure interface objects here.
    NSLog(@"%@ initWithContext", self);

}
return self;
}
- (IBAction)butRoute
{
     Methods *mt = [[Methods alloc]init];
    [mt notif:@"ARRIVING!"];
    //***** If I call this method, my code won't compile!!! *****

}

- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
NSLog(@"%@ will activate", self);
}

- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
NSLog(@"%@ did deactivate", self);
}

@end

The error I get is: Error

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check the target for your Methods class and make sure it is in your watch kit extensions target.

enter image description here

Alternately, look at building a framework for your shared classes. https://developer.apple.com/videos/wwdc/2014/?id=416


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...