【问题标题】:Make request from apple watch requests via ios app通过 ios 应用从 Apple Watch 请求中发出请求
【发布时间】:2017-11-29 13:35:49
【问题描述】:

现在我正在开发 Apple Watch 扩展程序并使用 WatchConnectivity。 我可以向 ios app 发送消息 ios app 发出请求吗?

谁可以向服务器 ios 应用或手表扩展发出请求?

附:使用 AFNetworking 与服务器一起工作。

谢谢

【问题讨论】:

    标签: objective-c networking watchos watchconnectivity


    【解决方案1】:

    您可以使用此方法向 ios App 发送通知以发出请求

    [[WCSession defaultSession] sendMessage:dictSendMessage replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyMessage) {
    } errorHandler:^(NSError * _Nonnull error) {
    
        }];
    

    您可以在 ios 应用程序中使用此委托方法接收该通知

    -(void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message replyHandler:(void (^)(NSDictionary<NSString *,id> * _Nonnull))replyHandler
    {
    }
    

    注意:您也可以在手表应用程序的帮助下自行向服务器请求

    NSURLSessionDataTask *taskDownload = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
        {
    }];
    // Start the task.
        [taskDownload resume];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 2022-11-26
      • 2021-06-12
      • 2018-04-25
      相关资源
      最近更新 更多