1

我对 iOS 开发相当陌生,我一直想知道在 iOS 4 上运行我的应用程序的用户是否会尝试运行以下代码:

//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.");
    }];
}

会发生什么?应用程序会因错误而终止,还是代码不会运行?以及如何正确实现特定于操作系统的功能?我会使用这样的东西吗:

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

3 回答 3

7

如果您编写 iOS5 功能而不检查它们是否可用,它将在 iOS 4 上崩溃。尝试像这样实现 Twitter

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.

于 2012-08-11T05:24:38.743 回答
1

我想它会与任何其他 api 一样工作。如果您链接的函数不在以前的版本中,程序将在尝试调用该函数时崩溃。因此,正如您所演示的,使用版本开关来避免崩溃。

于 2012-08-11T04:21:30.777 回答
1

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

于 2012-08-11T08:00:23.857 回答