ecnepsnai
ecnepsnai

Reputation: 2026

What will happen to users running a lower version of IOS if new code is called?

I am fairly new to iOS Development and I've always wondered if a user running my application on iOS 4 were to try and run this code:

//POST TWEET//
- (void)showTweetSheet
{
    TWTweetComposeViewController *tweetSheet =
    [[TWTweetComposeViewController alloc] init];
    tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result) {
        switch(result) {
            case TWTweetComposeViewControllerResultCancelled:
                break;
            case TWTweetComposeViewControllerResultDone:
                break;
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self dismissViewControllerAnimated:YES completion:^{
                NSLog(@"Tweet Sheet has been dismissed.");
            }];
        });
    };
    [tweetSheet setInitialText:@"Check out this cool picture I found on @Pickr_"];
    //  Add an URL to the Tweet.  You can add multiple URLs.
    if (![tweetSheet addURL:[NSURL URLWithString:ImageHost]]){
        NSLog(@"Unable to add the URL!");
    }
    [self presentViewController:tweetSheet animated:YES completion:^{
        NSLog(@"Tweet sheet has been presented.");
    }];
}

What would happen? Would the application just terminate with an error or will the code just not run? And how do I properly implement features that are OS specific? Would I just use something like this:

NSString *DeviceVersion = [[UIDevice currentDevice] systemVersion];
int DeviceVersionInt = [DeviceVersion intValue];
if (DeviceVersionInt > 5)
{
    //do something.
}
else
{
    //don't do a thing.
}

Upvotes: 1

Views: 133

Answers (3)

WolfLink
WolfLink

Reputation: 3317

The app would crash. If you want to implement features based on iOS, you can use a variety of methods. See this question.

Upvotes: 1

Manish Agrawal
Manish Agrawal

Reputation: 11037

It will crash on iOS 4 if you write iOS5 features without checking if they are available or not. Try to implement Twitter like this

Class twClass = NSClassFromString(@"TWTweetComposeViewController");
if (!twClass) // Framework not available, older iOS
{
    //use iOS4 SDK to implement Twitter framework
}
else {
    //use Apple provided default Twitter framework

}

Make sure you have added Twitter Framework with weak link.

Upvotes: 7

chacham15
chacham15

Reputation: 14281

Id imagine that it would work the same as with any other api. If you link against a function which is not in a previous version, the program will crash on an attempt to call the function. Therefore, version switches are used, as you demonstrated, to avoid crashes.

Upvotes: 1

Related Questions