簡體   English   中英

將twitter集成到iOS 5中,但保持與舊iOS的向后兼容性

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

按照這個關於如何將twitter集成到您的應用程序的精彩教程 我知道程序員在iOS 5之前還有其他方式用於集成twitter,但我的問題是:

我的應用程序支持iOS 3.0+,所以如果我只使用iOS 5的方式集成twitter,這將如何影響不使用iOS 5的用戶? 它甚至會為他們工作嗎?

謝謝!

如果您只為iOS 5用戶提供Twitter,那么您可以檢查Twitter是否可用:

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

此外,請確保在添加Twitter框架時將其設置為可選。

由於twitter app / integration僅在iOS 5中可用,因此官方API框架無法運行

一個好的解決方案是使用ShareKit ,這是一個免費的API,允許您集成twitter,facebook和其他社交網絡支持。

你應該看看DETweetComposeViewController 我們為此目的建造了它。 它是TWTweetComposeViewController的iOS4兼容重新實現。

使用弱鏈接和一些代碼,如下所示:

 - (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