WatchKit
バックオフィスからインターフェースに情報をロードしたいと思いますREST
。ホスト アプリを通過する URL 要求を実行するための高速な方法はありますか?iOS
それとも、本来の機能を利用して特定のプロトコルを作成する必要がありWatchConnectivity
ますか?
4 に答える
0
WatchKit 拡張機能から直接 NSURLSession を使用する必要があります。
于 2015-10-11T02:47:37.627 に答える
0
Apple の例はhttps://developer.apple.com/videos/play/wwdc2015-228/?time=345を参照してください。
Apple の例では、拡張機能をスリープ状態にする必要がある場合に、セマフォも使用していますが、これについては以下では省略しています。
以下のパターンに従うと、時計から直接目的のサービスをヒットできます。
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
[processInfo performExpiringActivityWithReason:@"networkReq" usingBlock:^(BOOL expired) {
if (!expired){
NSLog(@"we have an assertion");
NSTimeInterval secondsInThreeHours = 3 * 60 * 60;
NSURL *forecast = [NSURL URLWithString:@"http::address"];
NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:forecast
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
// handle response
}] resume];
else{
NSLog(@"Not background assertion or we are out of time");
}
}];
于 2016-01-31T21:34:43.753 に答える