我正在尝试通过NSInputStream
and获取更大的数据来实现 iOS Handoff NSOutputStream
。application(_:continue:restorationHandler:)
当我在我调用的方法中成功接收用户活动getContinuationStreams
但它总是失败并出现错误:
错误域 = NSCocoaErrorDomain 代码 = 4609 “由于网络不可用,无法完成切换。” UserInfo={NSUnderlyingError=0x17db43c0 {错误域=NSPOSIXErrorDomain Code=51“网络无法访问” UserInfo={NSLocalizedDescription=连接丢失}}}
字典userInfo
不NSUserActivity
为空,接收良好。
我遵循了Apple 的 Handoff Programming Guide和这篇文章。
这是我如何创建用户活动的代码示例:
func createUserActivity() {
self.userActivity = NSUserActivity(activityType: self.userActivityType)
self.userActivity?.supportsContinuationStreams = true;
self.userActivity?.delegate = self
self.userActivity?.becomeCurrent()
self.userActivity?.needsSave = true
}
在 AppDelegate 中,我收到如下用户活动:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
NSLog("continue userActivity %@", userActivity.userInfo!)
if userActivity.supportsContinuationStreams {
userActivity.getContinuationStreams(completionHandler: { (inputStream, outputStream, error) in
if error != nil {
NSLog("\(type(of: self)), \(#function) \(error.debugDescription)")
} else {
if let inStream = inputStream {
self.receivedData = NSMutableData()
self.currentActivityType = userActivity.activityType
self.inputStream = inStream
self.inputStream.delegate = self
self.inputStream.schedule(in: RunLoop.main, forMode: RunLoopMode.defaultRunLoopMode)
self.inputStream.open()
}
}
})
}
return true
}
参数inputStream
和outputStream
始终为零。
我究竟做错了什么?有人有线索吗?