gpt4 book ai didi

ios - UIActivityViewController 完成处理程序在 tweet 失败时返回成功

转载 作者:IT王子 更新时间:2023-10-29 05:04:58 27 4
gpt4 key购买 nike

我正在使用 UIActivityViewController 来显示共享表,以便用户可以共享我的应用程序。我目前正在测试推文,我得到了一些意想不到的结果。第一次发推文,一切顺利。第二次,我收到一条重复的推文错误消息,这是意料之中的。问题是 completionWithItemsHandler 返回 success: Bool 作为 true!

我希望能够向用户显示我自己的个性化消息,而不是当前返回的大量消息。

这是我的代码:

@IBAction func ShareButtonTapped(sender: AnyObject) {
let textToShare = "I'm using Buzz! The new way to send emoji's, with sound, it's annoying, funny and amazing"
var url = NSURL(string: "-Image url masked out-")
var data = NSData(contentsOfURL: url!)
let image = UIImage(data: data!)
if let myWebsite = NSURL(string: "-redirect masked out-")
{
let objectsToShare = [textToShare, myWebsite]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.completionWithItemsHandler = {
(activity, success, items, error) in
println("Activity: \(activity) Success: \(success) Items: \(items) Error: \(error)")
}
self.presentViewController(activityVC, animated: true, completion: { () -> Void in

})
}
}

这是我的日志:

2015-01-27 11:10:58.021 Buzz[3239:813859] LaunchServices: invalidationHandler called
2015-01-27 11:10:58.052 Buzz[3239:813860] LaunchServices: invalidationHandler called Activity: com.apple.UIKit.activity.PostToTwitter Success: true Items: nil Error: nil
2015-01-27 11:11:04.134 Buzz[3239:813859] LaunchServices: invalidationHandler called
2015-01-27 11:11:09.182 Buzz[3239:813859] plugin com.apple.share.Twitter.post invalidated

最佳答案

Use completion handler like this For SWIFT 3 AND 4, iOS 10 AND 11 :

activityVC.completionWithItemsHandler = {(activityType: UIActivityType?, completed: Bool, returnedItems: [Any]?, error: Error?) in
if !completed {
// User canceled
return
}
// User completed activity
}

self.present(activityVC, animated: true, completion: nil)

关于ios - UIActivityViewController 完成处理程序在 tweet 失败时返回成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28169192/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com