有没有办法以编程方式获得我的应用程序的构建版本?我需要能够检测到用户何时通过AppStore更新了应用程序,以便执行一些代码进行调整
发布于 2013-06-03 09:37:57
您在Xcode目标摘要的"Version“字段中设置的值在这里:
Swift 3
let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
ObjC
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
斯威夫特2
let version = NSBundle.mainBundle().infoDictionary?["CFBundleShortVersionString"] as! String
和“构建”:
Swift 3
let build = Bundle.main.infoDictionary?[kCFBundleVersionKey as String] as? String
ObjC
NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
斯威夫特2
let build = NSBundle.mainBundle().infoDictionary?[kCFBundleVersionKey as String] as! String
发布于 2013-06-03 09:00:53
您可以尝试使用infoDictionary
NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
NSString *build = infoDictionary[(NSString*)kCFBundleVersionKey];
NSString *bundleName = infoDictionary[(NSString *)kCFBundleNameKey];
发布于 2016-03-10 23:10:13
在使用"Contact Us“按钮的MFMailComposeViewController
时,我使用以下代码从用户的电子邮件中获取格式化的HTML语言。它为我提供了开始帮助解决任何问题所需的所有信息:
struct utsname systemInfo;
uname(&systemInfo);
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSDate *date = [NSDate date];
[formatter setDateFormat:@"MM/dd/yyyy 'at' hh:mm a"];
NSString *dateString = [formatter stringFromDate:date];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width - 65.0;
NSString *comments = NSLocalizedString(@"Please write your comments below:", nil);
NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey];
NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion];
NSString *emailBody = [NSString stringWithFormat:@"<!DOCTYPE html><html><style> .div {background-color: lightgrey; width: %fpx; padding: 10px; border: 5px solid navy; margin: 2px;}</style><body><div class='div'><p><b>App:</b> %@</p><b><p>Device:</b> %@</p><b><p>iOS Version:</b> %@</p><b><p><p>App Version and Build:</b> %@ (%@)</p><b><p>Date:</b> %@</p> </p></div><font color='red'><b>%@</b></font><br><br></body></html>",screenWidth,appName,deviceModel,iOSVersion,version,build,dateString,comments];
[self setMessageBody:emailBody isHTML:YES];
下面是获取消息时的结果:
https://stackoverflow.com/questions/16888780
复制相似问题