昨天我参加了一个watchkit黑客马拉松,我在使用Google Maps API并发送本地通知的NSObject类上调用方法时遇到了一些问题。如果我从我的Watchkit扩展中调用此方法,则代码无法编译,但是如果我从ViewController调用,例如,一切都运行良好
#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
我得到的错误是:
答案 0 :(得分:9)
答案 1 :(得分:1)
我不知道您正在使用的xcode版本,但考虑到initWithContext方法不再有效。你应该使用:
- (void)awakeWithContext:(id)context
你不应该覆盖它,只需使用它。
答案 2 :(得分:0)
删除#import行并将其替换为WatchKit框架。