Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 406
Lucas Farah Avatar asked Dec 05 '25 12:12

Lucas Farah


1 Answers

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

like image 142
Stephen Johnson Avatar answered Dec 07 '25 04:12

Stephen Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!