标签:
Apple Watch -----------? iPhone
[WKInterfaceController openParentApplication:@{@"type":@"song", @"para":@{@"channelID":channelID}} reply:^(NSDictionary *replyInfo, NSError *error) {
if(replyInfo){
// 对iPhone返回的数据进行解档
NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:[replyInfo objectForKey:@"songs"]];
}
}];
该方法是 WatchKit里面用来调用iPhone主体的接口,对应的要在iPhone端的AppDelegate中实现:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply NS_AVAILABLE_IOS(8_2);
*注意 ios8.2+才有该方法。
iPhone ---------------? apple watch
#pragma mark - WatchKit Data
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo
reply:(void(^)(NSDictionary *replyInfo))reply {
NSString *type = userInfo[@"type"];
NSDictionary *para = userInfo[@"para"];
NSDictionary *response = nil;
if ([type isEqualToString:@"song"])
{
// response = @{@"songs":@"11111"};
NSArray *songArray = [NSArray arrayWithObjects: MySong1, Mysong2, nil];// Mysong 是自定义数据类型
respone = @{@"songs":[NSKeyedArchiver archivedDataWithRootObject:songArray]};
}
reply(respone);
}
*****注意******
此处数据如果是不可序列化的,需进行可序列化处理。数据归档和解档要对应。
标签:
原文地址:http://my.oschina.net/lavzchen/blog/417818