ios 尝试从独立的Apple Watch应用程序发出网络请求

iqxoj9l9  于 2023-08-08  发布在  iOS
关注(0)|答案(1)|浏览(192)

当Apple Watch是独立应用程序时,即使Apple Watch连接到iPhone,也无法进行网络呼叫吗?我使用的是新的独立应用程序目标,它不附带可以发出WatchConnectivity请求的配对iOS应用程序。
我得到了“坏文件描述符”10次中的9次,这让我认为手表应用程序基本上 * 需要 * 一个iPhone来保证一定程度的连接(我的手表没有Hive,我不能连接到公共wifi热点)。
我拿错了吗?
示例代码片段用于再现此操作:

import Combine
import SwiftUI

var cancellables = Set<AnyCancellable>()

@main
struct NetworkTest_Watch_AppApp: App {

  var body: some Scene {
    WindowGroup {
      Text("Test")
        .task {
          let url = URL(string: "https://google.com")!
          let dataTaskPublisher = URLSession.shared.dataTaskPublisher(for: url)

          dataTaskPublisher
            .retry(3)
            .sink(receiveCompletion: { completion in
              print(completion)
            }, receiveValue: { response in
              print(response)
            })
            .store(in: &cancellables)
        }
    }
  }
}

字符串
日志失败示例:

2023-01-05 22:48:54.472214-0800 NetworkTest Watch App[809:862165] [scenes] unable to send desiredFidelity:Never response to desiredFidelityAction:<BLSDesiredFidelityAction: 0x16ed9090; info: 0x0; responder: <_BSActionResponder: 0x16ed93e0; active: YES; waiting: NO> clientInvalidated = NO;
clientEncoded = NO;
clientResponded = NO;
reply = <BSMachPortSendOnceRight: 0x16ed9a90; usable: NO; (809:0:send-once xpcCode) from (779:0:send-once take)>;
annulled = YES;>
2023-01-05 22:50:14.457958-0800 NetworkTest Watch App[809:862418] PDTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1> finished with error [9] Error Domain=NSPOSIXErrorDomain Code=9 "Bad file descriptor" UserInfo={_kCFStreamErrorCodeKey=9, NSErrorPeerAddressKey={length = 28, bytes = 0x1c1ef516 00000000 fd746572 6d6e7573 ... cbc268fa 00000000 }, _kCFStreamErrorDomainKey=1, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataPDTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>",
    "LocalDataTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataPDTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>}
2023-01-05 22:50:14.459136-0800 NetworkTest Watch App[809:862418] Task <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1> finished with error [9] Error Domain=NSPOSIXErrorDomain Code=9 "Bad file descriptor" UserInfo={_kCFStreamErrorCodeKey=9, NSErrorPeerAddressKey={length = 28, bytes = 0x1c1ef516 00000000 fd746572 6d6e7573 ... cbc268fa 00000000 }, _kCFStreamErrorDomainKey=1, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>",
    "LocalDataPDTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>",
    "LocalDataTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <42094D6F-56E0-45A9-9F47-53DB66453C9D>.<1>}

lnxxn5zx

lnxxn5zx1#

Target->WatchProject->General中,检查Supports Running Without iOS App Installation


的数据

相关问题