简体   繁体   English

将twitter集成到iOS 5中,但保持与旧iOS的向后兼容性

[英]Integrate twitter into iOS 5 but maintain backwards compatibility with older iOS

Been following this great tutorial on how to integrate twitter into your app. 按照这个关于如何将twitter集成到您的应用程序的精彩教程 I know there are other ways that programmers have used to integrate twitter before iOS 5 but my question is this: 我知道程序员在iOS 5之前还有其他方式用于集成twitter,但我的问题是:

My app supports iOS 3.0+ so if I integrate twitter using just the iOS 5 way of doing it, how will this affect my users that aren't using iOS 5? 我的应用程序支持iOS 3.0+,所以如果我只使用iOS 5的方式集成twitter,这将如何影响不使用iOS 5的用户? Will it even work for them? 它甚至会为他们工作吗?

Thanks! 谢谢!

If you are OK by only making Twitter available for iOS 5 users, you can check if Twitter is available with this: 如果您只为iOS 5用户提供Twitter,那么您可以检查Twitter是否可用:

// Don't forget to import Twitter!
#import <Twitter/Twitter.h>
....
if([TWTweetComposeViewController class] != nil) {
    // your code here
}

Also, make sure that when adding the Twitter framework you set it as optional. 此外,请确保在添加Twitter框架时将其设置为可选。

The official API framework wouldn't work unfortunately as the twitter app/integration is only available in iOS 5 由于twitter app / integration仅在iOS 5中可用,因此官方API框架无法运行

A good solution is to use ShareKit , a free API that allows you to integrate twitter, facebook and other social network support. 一个好的解决方案是使用ShareKit ,这是一个免费的API,允许您集成twitter,facebook和其他社交网络支持。

You should look into DETweetComposeViewController . 你应该看看DETweetComposeViewController We built it just for this purpose. 我们为此目的建造了它。 It is an iOS4 compatible re-implementation of the TWTweetComposeViewController. 它是TWTweetComposeViewController的iOS4兼容重新实现。

Use weak linking and some code like the following: 使用弱链接和一些代码,如下所示:

 - (void)tweet
{
Class tweeterClass = NSClassFromString(@"TWTweetComposeViewController");

if(tweeterClass != nil) {   
    if([TWTweetComposeViewController canSendTweet]) {
        TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
        tweetViewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
            if(result == TWTweetComposeViewControllerResultDone) {

            }
            [self dismissViewControllerAnimated:YES completion:nil];
        };

        [self presentViewController:tweetViewController animated:YES completion:nil];
    } else {
#if !(TARGET_IPHONE_SIMULATOR)
        [self displayAlert:@"You can't send a tweet right now, make sure your device has an internet connection and you have at least one Twitter account setup."];
#else
        NSString *tweetString = [NSString stringWithFormat:@"http://mobile.twitter.com/home?status=%@%@", [self urlEncode:@"Check out this awesome pic: "] ,[self urlEncode:[_blobTweet.shortUrl absoluteString]]];
        NSURL *tweetURL = [NSURL URLWithString:tweetString];
        if ([[UIApplication sharedApplication] canOpenURL:tweetURL]) { 
            [[UIApplication sharedApplication] openURL:tweetURL]; 
        }
#endif
    }
} else {        
    // no Twitter integration could default to third-party Twitter framework

}
}

@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM