本文介绍了UIActivityViewController 完成处理程序在推文失败时返回成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

I'm using a UIActivityViewController to display a share sheet so users can share my app. I'm currently testing tweets and i'm getting some unexpected results. On tweeting for the first time, all goes well. On the second time, i'm getting a duplicate tweet error message, which is expected. The problem is that the completionWithItemsHandler is returning success: Bool as true!

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

I want to be able to display my own personalised message to the user rather than the massive one that is returned currently.

这是我的代码:

@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
2015-01-27 11:10:58.052 嗡嗡声[3239:813860]LaunchServices:invalidationHandler 调用的 Activity:com.apple.UIKit.activity.PostToTwitter 成功:true 项目:nil 错误:nil
2015-01-27 11:11:04.134 Buzz [3239:813859] LaunchServices:调用了 invalidationHandler
2015-01-27 11:11:09.182 Buzz[3239:813859] 插件 com.apple.share.Twitter.post 失效

推荐答案

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)

这篇关于UIActivityViewController 完成处理程序在推文失败时返回成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:05