开发者

Identify device's IOS version dynamically [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Check iPhone iOS Version

I'm building an app that has an SMS composer (which isn't available in 3.0). How can I find the underlying device's OS version dynamically and make the SMS option available, and if not disable the functio开发者_运维百科n.


Here is the piece of code which will give you all the info about device

NSLog(@"uniqueIdentifier: %@", [[UIDevice currentDevice] uniqueIdentifier]);
    NSLog(@"name: %@", [[UIDevice currentDevice] name]);
    NSLog(@"systemName: %@", [[UIDevice currentDevice] systemName]);
    NSLog(@"systemVersion: %@", [[UIDevice currentDevice] systemVersion]);
    NSLog(@"model: %@", [[UIDevice currentDevice] model]);
    NSLog(@"localizedModel: %@", [[UIDevice currentDevice] localizedModel]);

you can get here the version number.

But i will suggest you to go with checking that the phone supports mail composer,sms or not like

Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));

if (messageClass != nil) {          
    // Check whether the current device is configured for sending SMS messages
    if ([messageClass canSendText])
    {
        MFMessageComposeViewController *msgpicker = [[MFMessageComposeViewController alloc] init];
        msgpicker.messageComposeDelegate = self;
        msgpicker.recipients = [NSArray arrayWithObject:[self.productInfoArray valueForKey:@"Phone"]]; // your recipient number or self for testing
        msgpicker.body = @"test from OS4";
        NSLog(@"chat view array  %@",[self.productInfoArray valueForKey:@"Phone"]);
        [self presentModalViewController:msgpicker animated:YES];
        [msgpicker release];
        NSLog(@"SMS fired");


    }
    else {      NSLog(@"chat view array  %@",[self.productInfoArray valueForKey:@"Phone"]);
        NSLog(@"Device not configured to send SMS.") ;
        UIAlertView *alert= [[UIAlertView alloc]initWithTitle:@"Status" message:@"Device not configured to send SMS." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel",nil];
        [alert show];
        [alert release];

    }
}

This will help to resolve your problem. Happy Coding Cheers................


The UIDevice class has a systemVersion property you can use to get the OS version. This'll return the version value such as 3.1 or 4.2. Guess you can use this to determine access to your SMS functionality.

@property (nonatomic, readonly, retain) NSString *systemVersion

Check out the reference for more info > http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html


I think you could use NSClassFromString(@"MFMessageComposeViewController") to see if the class is available.

(Caveat: You couldn't check for UIGestureRecognizer this way because Apple used private class with the same name. Same could be true for MFMessageComposeViewController.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜