本文共 821 字,大约阅读时间需要 2 分钟。
在Objective-C中,获取本机系统版本可以通过UIDevice类实现。以下是一个简单的代码示例,展示了如何获取并显示iOS设备的系统版本。
首先,需要导入必要的头文件:
#import
然后,创建一个AppDelegate类,继承于UIResponder,并实现UIApplicationDelegate协议:
@interface AppDelegate : UIResponder{ UIWindow *window; UILabel *versionLabel;}
在AppDelegate的初始化方法中,设置版本号显示:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options { [self.window makeKeyWindow]; // 获取系统版本 UIDevice *device = [UIDevice currentDevice]; NSString *systemVersion = [device.systemVersion stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; // 设置版本号显示 self.versionLabel.text = [NSString stringWithFormat:@"系统版本:%@", systemVersion]; return YES;} 在Xcode中,将上述代码整合到AppDelegate.m文件中,并确保所有必要的导入和设置已经完成。通过这种方式,你就可以轻松地在iOS设备上获取并显示系统版本信息。
转载地址:http://qfsfk.baihongyu.com/