ios 4应用崩溃Twitter.framework



我使用twitter使用Sharekit和IOS5,我使用它的类TWTweetComposeViewControllerClass

Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");
    if (TWTweetComposeViewControllerClass != nil) {
        if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
            UIViewController *twitterViewController = [[TWTweetComposeViewControllerClass alloc] init];
            [twitterViewController performSelector:@selector(setInitialText:) 
                                        withObject:NSLocalizedString(@"TwitterMessage", @"")];

            [self.navigationController presentModalViewController:twitterViewController animated:YES];
            [twitterViewController release];
        }
    } else {
        [SHK flushOfflineQueue];
        SHKItem *item = [SHKItem text:text];
        //[SHKTwitter shareItem:item];
        SHKActionSheet *actionsheet = [SHKActionSheet actionSheetForItem:item];
        [actionsheet showFromToolbar:self.navigationController.toolbar];
    }

在模拟器5.0上运行正常,但在模拟器4.3上崩溃,错误如下。

dyld: Library not loaded: /System/Library/Frameworks/Twitter.framework/Twitter
      Referenced from: /Users/indianic/Library/Application Support/iPhone Simulator/4.3.2/Applications/241167D0-62E0-4475-85FD-0B8253B4E456/demoFBTW.app/demoFBTW
      Reason: image not found

我如何解决这个问题。我试图将框架的依赖从Required更改为可选,但没有找到

看起来你找到了如何弱链接框架。假设你使用的是Xcode 4.2和LLVM3,你也可以简化这段代码,并在你使用它时修复一个bug:

#include <Twitter/Twitter.h>
// This line is no longer needed:
// Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

// this part can now be:
if ([TWTweetComposeViewController class] != nil) { // no need to look up class by string now
    // note previously you were checking if this class responds to 'canSendTweet'
    // but you never called the method to see if you can actually send the tweet
    if([TWTweetComposeViewController canSendTweet]) {
        // you can type this correctly now...
        TWTweetComposeViewController *twitterViewController = [[TWTweetComposeViewController alloc] init];
        // ... and call this method directly
        [twitterViewController setInitialText:NSLocalizedString(@"TwitterMessage", @"")]; 
        [self presentModalViewController:twitterViewController animated:YES];
        [twitterViewController release];
    }
}
... continue with the shareKit option

最新更新