3

我在我的 iOS 和 Mac 应用程序中采用 Handoff。iOS -> iOS 和 iOS -> Mac 运行完美!这很棒。但是,Mac -> iOS 永远不会工作。我已经在不同的机器上测试了 El Capitan 和 Sierra。如果我添加一个网页URL 作为后备,iOS 中的 Safari 会拾取该活动,但不会显示本机 iOS 应用程序。我在 Mac 应用程序中使用这段代码

class ViewController: NSViewController {  
    override func viewDidAppear() {  
        super.viewDidAppear()      
        self.startUserActivity()  
    }    
    func startUserActivity() {  
        let userActivity = NSUserActivity(activityType: "net.myapp.myactivitytype")  
        userActivity.isEligibleForHandoff = true  
        userActivity.isEligibleForSearch = false  
        userActivity.isEligibleForPublicIndexing = false  
        userActivity.title = "Handoff test"  
        userActivity.userInfo = ["key": "value"]  
        userActivity.requiredUserInfoKeys = Set<String>(arrayLiteral: "key")  
        userActivity.webpageURL = URL(string: "https://myapp.net/myurl") // I can pick this up in mobile safari  
        self.userActivity = userActivity  
    }    
    override func updateUserActivityState(_ userActivity: NSUserActivity) {  
        userActivity.addUserInfoEntries(from: ["key":"Updated value"])  
        super.updateUserActivityState(userActivity)  
    }  
} 

在 iOS 端,我已经使用 applinks:myapp.net 处理了通用链接,并尝试添加 activitycontinuation:myapp.net (以及在 apple-app-site-association 文件上的正确配置。这使我的本机应用程序获得了相应的url 来自 Mac 的 Safari,但 Native Mac 应用程序仍然无法切换到 Native iOS 应用程序。我没有想法,有人知道为什么会发生这种情况吗?在 iOS 上,我使用的是 10.2。顺便说一句,我不能t 让 Handoff 在 iOS 9 上完全可用。

最好的问候拉斐尔

4

2 回答 2

1

我终于解决了。答案与接受的答案所暗示的签署个人资料无关。

我向 Apple 报告了一份错误报告,解释了整个情况,Apple 告诉我,我的 iOS 应用程序的 info.plist 根本没有声明 NSUserActivityTypes,而我的 Mac 应用程序的 info.plist 正确声明了 NSUserActivityTypes,导致切换只能从 iOS 工作到Mac 和从来没有 Mac 到 iOS。

This issue is due to the iOS version of the app not claiming the activity type in the info.plist, resulting in the iOS device not knowing what app to give the handoff to.

在左侧导航面板的 Xcode 项目中,我打开 info.plist 并且 NSUserActivityTypes 确实已经存在。但是当我使用项目文件夹中的 Finder 搜索它时,我意识到我的项目中有多个 info.plist 文件。然后我用 Finder 进入我的项目文件夹并试图找到这个 info.plist 文件,但是当我在 projectName/projectName 中找到一个文件时,它打开了一个不同的 info.plist 文件,我最初无法通过 Xcode 项目导航器访问该文件。不同的 info.plist 文件没有 NSUserActivityTypes,所以我添加了它,woala~handoff 终于从 Mac 到 iOS 工作了!很奇怪,我的项目中有多个假的 info.plist。我的真实信息列表被 Xcode 隐藏了......

于 2018-07-24T05:58:10.897 回答
0

在我的情况下,问题是由于在对 Mac 应用程序进行代码签名时缺少权利造成的。运行时codesign -d --entitlements - /Applications/MyApp.app,它缺少与团队标识符相关的条目。这是 iOS 将 Mac Handoff 连接到其本地对应物的关键(而不是尝试使用相同 Handoff 标识符的其他流氓应用程序)

<key>com.apple.developer.team-identifier</key>
<string>MY_TEAM_ID</string>

要添加此权利,请在Dev Center中为您的应用程序创建一个Provisioning Profile,下载它并将其导入 Xcode 的手动签名中。在没有配置文件的情况下,无论是自动还是手动,它都对我不起作用(Xcode 将其声明为可选)

于 2018-06-27T16:43:57.767 回答