9

所以,我有空投功能,但如果用户按下接受,如果用户按下拒绝空投请求,我需要发生不同的事情。

目前,无论用户接受还是拒绝空投请求,都会发生相同的操作。

我正在使用

activityViewController.SetCompletionHandler(HandleActivityViewControllerCompletion);

有这个签名:

private async void HandleActivityViewControllerCompletion (NSString activityType, bool completed, NSExtensionItem[] returnedItems, NSError error)

问题是我不能使用这些参数。如果用户做出任何选择并且返回的项目为空,则 Completed 始终返回 true。

我可以使用或做什么来检测用户是否拒绝了 Airdrop 请求?

这适用于 Xamarin.iOS 应用程序,但 Swift/native iOS 中的答案也很好。

没有答案的类似 SO 问题: UIActivityViewController Airdrop - Check the status when 'sent' or 'declined'

4

1 回答 1

3

嗯,好吧,看来看水晶球是免不了回答这个问题了。

我在 iOS 10.3.3 上进行了尝试,无论 Airdrop 是否被其他设备接受或拒绝,这种方法的行为确实没有区别。

显然,到目前为止的completed布尔值意味着:“数据已提供给选定的活动”或“数据未提供给任何活动”。HandleActivityViewControllerCompletion它对应于共享表下方的按钮是“完成”还是“取消”。不幸的是,即使空投被拒绝,空投活动也会将此按钮设置为“完成”,这是有道理的,因为它“做了一些事情”。

我认为问题(设计方面)在于,通常情况下,活动(例如自定义活动)UIActivityViewController在调用activityDidFinish(_:). AidropActivity 显然很特别,它似乎根本没有这样做,它只是在连接通过时在其图标下方显示一个“已拒绝”指示符,但另一边,嗯,拒绝了。此外,它还会更改工作表的按钮。

Besides, the entire operation is asynchronous. To me it looks like the Airdrop activity calls its perform() or prepare(withActivityItems:) function, starts a remote connection asynchronously and immediately sets the button to "Done" while that is running (I don't even see a way for other activities to do that, but I didn't try). You can even press Done before the other side has accepted or declined, that won't abort the transfer. The Activity even gets notified (if the sheet wasn't yet closed with "Done") to update its icon.

All in all it appears to have special privileges, which makes sense, as the entire Airdrop functionality is special: It runs in the background. The activity merely passes it data and as soon as that's done, itself is done as well (regardless of outcome).

Of course I agree that this is insufficient, but I changing this would probably require Apple to change the API. So it'd be a feature request for you, I strongly doubt there's a (AppStore conform) workaround that I didn't think of...

于 2017-08-08T15:11:07.813 回答