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

前端之家收集整理的这篇文章主要介绍了ios – UIActivityViewController完成处理程序在tweet失败时返回成功前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_1@我正在使用UIActivityViewController显示一个共享表,以便用户可以共享我的应用程序.我正在测试推文,我收到了一些意想不到的结果.在第一次tweeting,一切顺利.第二次,我收到一个重复的tweet错误消息,这是预期的.问题是,completionWithItemsHandler正在返回成功: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

解决方法

SWIFT iOS 8.0>,您应该使用完成处理程序,如下所示:
self.presentViewController(activityVC,completion: nil)

activityVC.completionWithItemsHandler = {(activityType,completed:Bool,returnedItems:[AnyObject]?,error: NSError?) in

     // Return if cancelled
     if (!completed) {
         return
     }

     //activity complete
     //some code here


}

猜你在找的iOS相关文章