动态识别设备的iOS版本[重复]

问题描述 投票:0回答:3

可能重复:
如何查看iOS版本?

我正在构建一个具有短信编辑器的应用程序(3.0 中不可用)。 如何动态查找底层设备的操作系统版本并使短信选项可用,如果不禁用该功能?

iphone ios ios4
3个回答
5
投票

这是一段代码,将为您提供有关设备的所有信息

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]);

您可以在此处获取版本号。

但我建议您检查手机是否支持邮件编辑器、短信 喜欢

类 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];

    }
}

这将有助于解决您的问题。 快乐编码 干杯......


4
投票

UIDevice 类有一个 systemVersion 属性,您可以使用它来获取操作系统版本。这将返回版本值,例如 3.1 或 4.2。我猜您可以使用它来确定对短信功能的访问。

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

查看参考资料以获取更多信息 > http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html


3
投票

我想你可以使用

NSClassFromString(@"MFMessageComposeViewController")
来查看该课程是否可用。

(警告:您无法通过这种方式检查

UIGestureRecognizer
,因为 Apple 使用了同名的私有类。
MFMessageComposeViewController
也可能如此。)

© www.soinside.com 2019 - 2024. All rights reserved.