【问题标题】:App crashes on ios 4.X for framework Twitter.framework应用程序在 iOS 4.X 上因 Twitter.framework 框架崩溃
【发布时间】:2012-01-28 08:05:14
【问题描述】:

我通过 Sharekit 使用 Twitter,对于 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 更改为 Optional,但没有找到

【问题讨论】:

  • Twitter.framework 只支持 ios 5 不支持 ios4
  • 所以我不能将TWTweetComposeViewControllerClass 用于同时使用 ios5 和 ios4 的应用程序?因为我正在为 使用sharekit
  • “...但没有找到”。 “没有找到”是什么意思?你的意思是在 Xcode 中找不到选项?
  • 是的,我没有找到框架的依赖选项
  • 我知道了。要使用weak linking,我们需要将框架从Required改为Option,即BuildPhases->LinkBinaryWithLibraries->使其成为可选

标签: iphone ios4 twitter ios5 sharekit


【解决方案1】:

您似乎找到了如何弱链接框架。假设您使用的是 Xcode 4.2 和 LLVM3,您还可以稍微简化此代码并修复您在使用它时遇到的错误:

#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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    相关资源
    最近更新 更多