我有一个手表应用程序正在更新的手表os 2。发送消息不会唤醒父应用程序。根据转换文档,是这样在后台唤醒父级的。
“iOS应用程序总是被认为是可触及的,从你的手表应用程序中调用这个方法会在需要时唤醒后台的iOS应用程序。”
有人有这个问题吗?获取数据的唯一方法是已经打开了父应用程序。
另一件奇怪的事情是,手表应用程序改变了父应用程序的uitableview。当-(IBAction)yesterdaySales:(Id)发件人在手表上被调用时,它将更改父应用程序UITableView而不是手表表视图。
InterfaceController.m
#import "InterfaceController.h"
#import "MyRowController.h"
#import "ftDateParser.h"
@import WatchKit;
#import <WatchConnectivity/WatchConnectivity.h>
@interface InterfaceController() <WCSessionDelegate>
{
IBOutlet WKInterfaceDevice *it;
BOOL tday;
IBOutlet WKInterfaceLabel *lblCompany;
}
@end
@implementation InterfaceController
@synthesize myTable = _myTable;
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
if([WCSession isSupported]){
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
}
//[self requestInfoPhone];
[self getToday];
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
-(void)requestInfoPhone{
NSDictionary *dic = @{@"request":@"ySales"};
[[WCSession defaultSession] sendMessage:dic
replyHandler:^(NSDictionary *replyInfo){
NSLog(@"The Reply: %@", replyInfo);
NSDictionary *location = replyInfo;
NSString *name = location[@"label"];
NSString *totalSales = location[@"totalSales"];
// NSString *test2 = location[@"rowText"];
NSMutableArray *sales = [[NSMutableArray alloc]init];
NSMutableArray *storeNames = [[NSMutableArray alloc]init];
sales = location[@"rowText"];
storeNames = location[@"storeNames"];
[self loadTable:sales names:storeNames company:name];
[_labelName setText:name];
[_labelTotalSales setText:totalSales];
tday = YES;
}
errorHandler:^(NSError *error){
NSLog(@"%@", error);
}
];
}
-(void)loadTable:(NSMutableArray*)tester names:(NSMutableArray*)names company:(NSString *)company{
[_myTable setNumberOfRows:[tester count] withRowType:@"row"];
[_labelName setText:company];
for (int i = 0; i < [tester count]; i++) {
MyRowController *vc = [_myTable rowControllerAtIndex:i];
[vc.testLabel setText:[ftDateParser currencyFormat: tester[i]]];
[vc.nameLabel setText:[ftDateParser parseName:names[i]]];
}
[_myTable scrollToRowAtIndex:(0)];
}
-(IBAction)yesterdaySales:(id)sender{
if (tday) {
[_ydaySales setTitle:@"Today Sales"];
[self requestInfoPhone];
}
else{
[_ydaySales setTitle:@"Yesterday Sales"];
[self getToday];
}
}
-(void)getToday{
NSDictionary *dic = @{@"request":@"todaySales"};
[[WCSession defaultSession] sendMessage:dic
replyHandler:^(NSDictionary *replyInfo){
NSDictionary *location = replyInfo;
NSString *name = location[@"label"];
NSString *totalSales = location[@"totalSales"];
// NSString *test2 = location[@"rowText"];
NSMutableArray *sales = [[NSMutableArray alloc]init];
NSMutableArray *storeNames = [[NSMutableArray alloc]init];
sales = location[@"rowText"];
storeNames = location[@"storeNames"];
[self loadTable:sales names:storeNames company:name];
[_labelName setText:name];
[_labelTotalSales setText:totalSales];
tday = YES;
}
errorHandler:^(NSError *error){
NSLog(@"%@", error);
}
];
}
@endParent.m
-(void)setUpAppForWatch{
done = NO;
if([WCSession isSupported]){
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
}
}
-(void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message replyHandler:(void (^)(NSDictionary<NSString *,id> * _Nonnull))replyHandler{
/*UIApplication *application = [UIApplication sharedApplication];
__block UIBackgroundTaskIdentifier identifier = UIBackgroundTaskInvalid;
dispatch_block_t endBlock = ^ {
if (identifier != UIBackgroundTaskInvalid) {
[application endBackgroundTask:identifier];
}
identifier = UIBackgroundTaskInvalid;
};
identifier = [application beginBackgroundTaskWithExpirationHandler:endBlock];*/
[self setUpAppForWatch];
[self getTheDate];
startDate = todayDay;
endDate = tomorrow;
//[self getTodaySalesforWatch];
NSString *currency = [ftDateParser currencyFormat:totalSales];
NSDictionary *dic = @{@"label": [NSString stringWithFormat:@"%@", @"Town Crier, Inc."],
@"totalSales": currency,
@"rowText": storeSalesData,//[NSString stringWithFormat:@"%@", currency]
@"storeNames":storeNames
};
NSString *request = [message objectForKey:@"request"];
if ([request isEqualToString:@"todaySales"]) {
[self getTodaySalesforWatch];
}
else if ([request isEqualToString:@"ySales"]){
[self connectToWebService];
}
if (done) {
replyHandler(dic);
}
}编辑:
也许父应用程序的变化以前就发生过,但我不知道,因为这个应用程序是在后台运行的。仍然无法唤醒父应用程序。
发布于 2016-03-28 07:08:46
您没有链接到问题顶部的引用源,但它一定是指WatchKit 1的WatchKit方法。运行WatchOS 2.0的设备不能调用openParentApplication。
您在问题中的代码中实现的方法是针对WCSession的,它只适用于同时运行的WatchKit应用程序扩展和iOS应用程序之间的即时通信。这种方法不会导致您的iOS应用程序启动,无论是在后台还是前台。如果两个应用程序当时都没有运行,则必须使用其他异步通信方法。
https://stackoverflow.com/questions/32788707
复制相似问题