Twitter.framework Problems building for both iOS4.3 and iOS5.0

I'm running up against problems trying to incorporate some iOS5-specific libraries into an app targeted at both iOS5 and iOS4.3. I've gone through the following steps:

  • weakly-linked the Twitter framework by setting it as optional in 'Link Binary with Libraries"

  • added it as a framework for the iOS5.0 SDK in Other Linker Flags with `-framework Twitter.framework'

  • conditionally linked the framework in the class header:

    #if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
    #import <Twitter/Twitter.h>
    #import <Accounts/Accounts.h>
    #endif
    
  • then in the method itself, I'm then checking whether the user's set up for Twitter:

    if ([TWTweetComposeViewController class]) {
        self.canTweet = [TWTweetComposeViewController canSendTweet];
    }
    

This works beautifully on both the 5.0 and 4.3 simulators. However, I've got problems getting it to run on, or archive for, actual devices.

When I've got either a 3GS running 5.0, or a 4 running 5.0 attached, both show up twice in the Scheme dropdown. Selecting the top one, and attempting build or run the project fails with an Use of unidentified identifier 'TWTweetComposeViewController' error.

Using the second device entry, the build fails with a ld: framework not found Twitter.framework error.

I'm sure there's something I'm missing here, but I'm stumped. Can anyone advise?

link | improve this question

43% accept rate
 
try accept some answers first 0% accept rate –  AhmadTK  Oct 15 '11 at 13:58
feedback

3 Answers

up vote 0 down vote accepted

If you are using a week linking then you have to check first availability of API using NSClassFromString, respondsToSelector, instancesRespondToSelector etc. So, change your if condition. First try to get your class object using above specified runtime function.
here is a link explaining in detail how to do such. link

link | improve this answer
 
Thanks - have amended that in line with the suggestion. It seems like I'm hitting two issues here though, as I've got the the framework not found error as well... –  TimD  Oct 15 '11 at 14:32
feedback

Further digging into the error thrown back by the compiler suggested that it was ignoring the weak link flag. Although I've no idea how or why, it was fixed by a reinstallation of XCode.

link | improve this answer
 
feedback

The code for presenting twitter controller

Before this you have to add the frameworks as optional and make the import in h file if iOS is min iOS 5

Class TWTweetComposeViewControllerClass = NSClassFromString(@"TWTweetComposeViewController");

     if (TWTweetComposeViewControllerClass != nil) {
          if([TWTweetComposeViewControllerClass respondsToSelector:@selector(canSendTweet)]) {
              UIViewController *twitterViewController = [[TWTweetComposeViewControllerClass alloc] init];

              [twitterViewController performSelector:@selector(setInitialText:) 
                                          withObject:NSLocalizedString(@"TwitterMessage", @"")];
              [twitterViewController performSelector:@selector(addURL:) 
                                          withObject:url];

               [twitterViewController performSelector:@selector(addImage:) 
                                           withObject:[UIImage imageNamed:@"yourImage.png"]];
                [self.navigationController presentModalViewController:twitterViewController animated:YES];
                [twitterViewController release];
                }
            } 
link | improve this answer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值