当tweet失败时,UIActivityViewController完成处理程序返回成功 [英] UIActivityViewController completion handler returns success when tweet has failed

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

问题描述

我正在使用UIActivityViewController来显示共享表,以便用户可以共享我的应用。我正在测试推文,我得到了一些意想不到的结果。在第一次发推文时,一切顺利。在第二次,我得到一个重复的推文错误消息,这是预期的。问题是completionWithItemsHandler返回成功: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 Buzz [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无效

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 3 AND 4,iOS 10和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)

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆