天天看點

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

2 down vote favorite share [fb] share [tw] 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?

iphone  objective-c  ios  xcode  ios5

link | improve this question asked  Oct 15 '11 at 13:29
Twitter.framework Problems building for both iOS4.3 and iOS5.0

TimD

137 1 5

43% accept rate

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

3 Answers

active oldest votes

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 answered  Oct 15 '11 at 13:52
Twitter.framework Problems building for both iOS4.3 and iOS5.0

Armaan

327 7

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
Twitter.framework Problems building for both iOS4.3 and iOS5.0
up vote 0 down vote 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 answered  Oct 18 '11 at 0:55
Twitter.framework Problems building for both iOS4.3 and iOS5.0

TimD

137 1 5

feedback
up vote 0 down vote

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 answered  Dec 22 '11 at 9:16
Twitter.framework Problems building for both iOS4.3 and iOS5.0

Terente Ionut Alexandru

4,648 1 5 21