objective-c tag - TWOSweetComposeViewController在IOS6中已棄用




twitter (3)

是的,您應該在iOS 6上使用社交框架 。這要歸功於現在iOS上的Facebook集成。 您可以從那裡使用Twitter和Facebook。

我的代碼按預期工作只是因為我需要擺脫這個警告消息。 在IOS6中不推薦使用TWTeetComposeViewController。 是否在ios6中替換了這個內置視圖控制器?

這是我的示例代碼。

if ([TWTweetComposeViewController canSendTweet]) {
    // Initialize Tweet Compose View Controller
    TWTweetComposeViewController *vc = [[TWTweetComposeViewController alloc] init];
    // Settin The Initial Text
    [vc setInitialText:@"This tweet was sent using the new Twitter framework available in iOS 5."];
    // Adding an Image
    UIImage *image = [UIImage imageNamed:@"sample.jpg"];
    [vc addImage:image];
    // Adding a URL
    NSURL *url = [NSURL URLWithString:@"http://mobile.tutsplus.com"];
    [vc addURL:url];
    // Setting a Completing Handler
    [vc setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
        [self dismissModalViewControllerAnimated:YES];
    }];
    // Display Tweet Compose View Controller Modally
    [self presentViewController:vc animated:YES completion:nil];
} else {
    // Show Alert View When The Application Cannot Send Tweets
    NSString *message = @"The application cannot send a tweet at the moment. This is because it cannot reach Twitter or you don't have a Twitter account associated with this device.";
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:message delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
    [alertView show];
}

在iOS 5和iOS 6之間使用社交網絡有一些變化。
1.關於圖書館:在iOS 6中,我們使用社交框架而不是Twitter框架。
2.我們使用SLComposeViewController而不是TWTweetComposeViewController。
3.請使用以下代碼比較一些api:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {

        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

        SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
            if (result == SLComposeViewControllerResultCancelled) {

                NSLog(@"Cancelled");

            } else

            {
                NSLog(@"Done");
            }

            [controller dismissViewControllerAnimated:YES completion:Nil];
        };
        controller.completionHandler =myBlock;

        //Adding the Text to the facebook post value from iOS
        [controller setInitialText:@"Test Post from mobile.safilsunny.com"];

        //Adding the URL to the facebook post value from iOS

        [controller addURL:[NSURL URLWithString:@"http://www.mobile.safilsunny.com"]];

        //Adding the Image to the facebook post value from iOS

        [controller addImage:[UIImage imageNamed:@"fb.png"]];

        [self presentViewController:controller animated:YES completion:Nil];

    }
    else{
        NSLog(@"UnAvailable");
    }

只是有一些差異,但它們更偉大。

優惠: - safilsunny提示: http://www.mobile.safilsunny.com/integrating-facebook-ios-6/http://www.mobile.safilsunny.com/integrating-facebook-ios-6/

謝謝,


回答我自己的問題大約2年後,但是......

它使用協議擴展,所以你可以做到這一點,沒有任何額外的代碼,所有的類。

/*

Prerequisites
-------------
- In IB set the view's class to the type hook up any IBOutlets
- In IB ensure the file's owner is blank

*/

public protocol CreatedFromNib {
    static func createFromNib() -> Self?
    static func nibName() -> String?
}

extension UIView: CreatedFromNib { }

public extension CreatedFromNib where Self: UIView {

    public static func createFromNib() -> Self? {
        guard let nibName = nibName() else { return nil }
        guard let view = NSBundle.mainBundle().loadNibNamed(nibName, owner: nil, options: nil).last as? Self else { return nil }
        return view
    }

    public static func nibName() -> String? {
        guard let n = NSStringFromClass(Self.self).componentsSeparatedByString(".").last else { return nil }
        return n
    }
}

// Usage:
let myView = MyView().createFromNib()






objective-c ios twitter ios6