mando un dizionario per un app iOS utilizzando:Condividere i dati tra l'orologio app e iOS in watchOS2
- (void)sendMessage:(NSDictionary<NSString *, id> *)message
replyHandler:(nullable void (^)(NSDictionary<NSString *, id> *replyMessage))replyHandler
errorHandler:(nullable void (^)(NSError *error))errorHandler;
ma sto ottenendo un errore con questo. Voglio sapere in che modo la nostra app principale gestisce questa richiesta in watchOS2.
In watchOS1, ho utilizzato openParentApplication
per ottenere dati dall'app padre e Appdelegate
ha avuto un handleWatchKitExtensionRequest
per gestire tale richiesta. Come gestiamo questo in watchOS2?
mio interfaccia controller:
- (void)awakeWithContext:(id)context
{
[super awakeWithContext:context];
if([WCSession isSupported])
{
self.watchSession = [WCSession defaultSession];
self.watchSession.delegate = self;
[self.watchSession activateSession];
}
[self sendRequestWithActionType:@"InitialView"];
}
-(void)sendRequestWithActionType:(NSString *)action
{
NSDictionary *requst = @{@"request":action};
[[WCSession defaultSession] sendMessage:requst
replyHandler:^(NSDictionary *replyHandler) {
[self setTextForLabelWithData:[replyHandler valueForKey:@"response"]];
}
errorHandler:^(NSError *error) {
NSLog(@"");
}
];
}
È dovrebbe essere il controllo reachabl e prima di usare sendMessage. Che errore ottieni? – ccjensen
Voglio ottenere rispostaHandler dictionary.tell me cosa dovrei fare in app iOS.Penso, dovremmo usare - sessione (nullo): (noncontenuta WCSession *) session didReceiveMessage: (nonnull NSDictionary *) messaggio replyHandler: (nonnull void (^) (NSDictionary * __nonnull)) replyHandler dammi un esempio per questo – PramukaD