TWTweetComposeViewController

TWTweetComposeViewController

本文介绍了如何在iOS中改进我的TWTweetComposeViewController代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了以下代码来进行Twitter共享。在我的代码中,我尝试测试iOS 5,如果这不起作用,我将回到使用ShareKit的Twitter代码进行共享的旧方式。

I have implemented the following code to do a Twitter Share. In my code I try to test for iOS 5 and if that does not work, I go back to the old way of sharing using ShareKit's Twitter code.

我展示了代码对同事,他建议我的代码可能有缺陷,我需要做两件事:

I showed the code to a co worker and he suggested that my code may have flaws and that I need to do two things:


  1. 做一个正确的运行时检查?? (因为它可能会在IOS 4及更早版本上崩溃)即使它没有崩溃。

  2. 弱链接Twitter框架工作

有人可以解释一下正确的运行时检查是什么吗?为什么弱链接?

Can someone kindly explain what a proper run time check would be? and Why Weak Link?

NSString *text = [NSString stringWithFormat:@"@Awesome chart: %@", self.titleLabel.text];







if ([TWTweetComposeViewController canSendTweet])
{

    TWTweetComposeViewController *tweetComposeViewController = [[TWTweetComposeViewController alloc] init];
    [tweetComposeViewController setInitialText:text];
    [tweetComposeViewController addImage:image];
    [tweetComposeViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result){

        dispatch_async(dispatch_get_main_queue(), ^{
            [self dismissModalViewControllerAnimated:YES];
            if (result == TWTweetComposeViewControllerResultDone)
            {
                NSLog(@"iOS 5 onwards Twitter share complete");
            }
        });
    }];

    [self presentViewController:tweetComposeViewController
                       animated:YES
                     completion:^{ }];
}
else
{
    SHKItem *item = [SHKItem image:image title:text];

    // Share the message.
    [SHKTwitter shareItem:item];
    NSLog(@"Device does not support Twitter library");
    }
}


推荐答案

A弱链接仅仅意味着框架不需要在设备上。或者换句话说,当您将框架添加到项目中时,应用程序将要求该框架位于设备上。因此,如果你需要一个框架,而不是,那么应用程序将崩溃。在您的情况下,如果您希望应用程序在iOS 5之前的iOS版本(即iOS 4.x)上运行,您可能希望弱链接Twitter框架。

A weak link simply means the a framework is not required to be on the device. Or put another way, when you add frameworks to your project, the app will require that framework to be on the device. So if you require a framework to be there, and it isn't, then the app will crash. In your case, you would want to weak link the twitter framework if you want the app to run on iOS version prior to iOS 5 (ie iOS 4.x).

正确的运行时检查意味着您应该将应用程序加载到您的设备上(运行iOS 5或更高版本)并测试应用程序的推特功能。如果它崩溃,那么你知道你有问题。

A proper run time check means you should load the app onto your device (running iOS 5 or later) and test the twitter feature of your app. If it crashes, then you know you have a problem.

我浏览了你的代码,一切看起来都很好。我没有通过我的编译器运行它,所以我不能说语法错误等。我要做的一个改变是:

I skimmed your code and everything looks fine. I didn't run it through my complier though so I can't speak for syntax errors and such. The one change I would make is:

if([TWTweetComposeViewController canSendTweet])

 Class twClass = NSClassFromString(@"TWTweetComposeViewController");
 if (!twClass) // Framework not available, older iOS
    return;

我使用它的原因是,从字面上检查框架是否在该设备上,而 canSendTweet 检查用户是否已登录。所以我不想将未登录的用户与其设备不支持i​​OS 5的用户混淆。

The reason why I use that is becuase that literally checks if the framework is on that device, while canSendTweet checks if the user is logged in. So I don't want to confuse a user not being logged in with a user whose device doesn't support Twitter with iOS 5.

如果您需要帮助,请告诉我。

Let me know if you need anymore help.

这篇关于如何在iOS中改进我的TWTweetComposeViewController代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 22:00