创建用于与 Apple Watch OS2 共享照片的架构

Creating Architecture for Sharing Photos with Apple Watch OS2

我正在尝试找出将 10 多张照片从 iOS 应用程序共享到使用 watchOS 2 的 Apple Watch 应用程序的正确方法。

我想在后台传输这些图像,这样用户就不必打开 iOS 应用程序来查看照片。

我试过从 Facebook 查询照片并通过 transferUserInfo() 将它们发送到手表,但负载太大:

FBSDKGraphRequest(graphPath: "me/photos?limit=2", parameters:["fields": "name, source"]).startWithCompletionHandler({ (connection, result, error) -> Void in
    if (error != nil){
        print(error.description)
    }
    else {
        var arr = [NSData]()

        for res in result["data"] as! NSArray {
            if let string = res["source"] as? String {
                if let url = NSURL(string: string) {
                    if let data = NSData(contentsOfURL: url){
                        arr.append(data)
                    }
                }
            }
        }
        print(arr)
        if arr.count > 0 {
            self.session.transferUserInfo(["image" : arr])
        }

    }
})

我应该如何着手做这件事?

WCSession 文档中提到了正确的方法:

Use the transferFile:metadata: method to transfer files in the background. Use this method in cases where you want to send more than a dictionary of values. For example, use this method to send images or file-based documents.

图像将在后台线程上异步传送到手表。 session:didReceiveFile:手表接收到图片成功时调用

确保在图像中包含(日期)元数据,并从手表中删除不再属于最近 10 次 Facebook 上传的任何现有图像。