获取iOS项目名称及版本号

34 篇文章 0 订阅

NSString *executableFile = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey];    //获取项目名称

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];      //获取项目版本号

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; CFShow(infoDictionary);// app名称

 NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"]; // app版本 

NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"]; // app build版本

 NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];

以上转自:http://my.oschina.net/notting/blog/213501



APP版本更新的解决方法

如果我们需要实现版本的 app 自动更新,那么我们需要获取当前运行程序的版本信息和 appstore 里发布的最新版本信息。

当前运行程序的版本信息,可以在 mainBundle 里面获取:

NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];

NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];

而 appstore 里发布的最新版本信息获取稍微复杂一些,有两种方案,思路都是一样的:

其一:在某个服务器上存储最新发布的版本信息,需要的时候向该服务器查询;

其二:在需要的时候向 appstore 查询;

在这里我来介绍第二种方法:向 appstore 查询应用程序信息,包括作者,版本,app 介绍页面地址等信息。

英文好的同学可以参考 apple 的文档:www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

具体步骤如下:

1,用 POST 方式发送请求:

http://itunes.apple.com/search?term=你的应用程序名称&entity=software

更加精准的做法是根据 app 的 id 来查找:

http://itunes.apple.com/lookup?id=你的应用程序的ID

如果是中国地区的程序,用这个:http://itunes.apple.com/cn/lookup?id=

2,从获得的 response 数据中解析需要的数据。因为从 appstore 查询得到的信息是 JSON 格式的,所以需要经过解析。解析之后得到的原始数据就是如下这个样子的:

{

resultCount = 1;

results = (

{

artistId = 301724683;

artistName = Citibank;

artistViewUrl = "http://itunes.apple.com/us/artist/citibank/id301724683?uo=4";

artworkUrl100 = "http://a5.mzstatic.com/us/r1000/117/Purple/a1/85/a9/mzl.hvwnfdkw.png";

artworkUrl512 = "http://a5.mzstatic.com/us/r1000/117/Purple/a1/85/a9/mzl.hvwnfdkw.png";

artworkUrl60 = "http://a2.mzstatic.com/us/r1000/099/Purple/67/86/7e/mzi.utfdvrgy.png";

averageUserRating = "3.5";

averageUserRatingForCurrentVersion = 5;

contentAdvisoryRating = "4+";

currency = USD;

description = "Description of you app.";

features = (

iosUniversal

);

fileSizeBytes = 4141195;

genreIds = (

6015

);

genres = (

Finance

);

ipadScreenshotUrls = (

"http://a1.mzstatic.com/us/r1000/095/Purple/e0/a6/17/mzl.pbbxcjzt.1024x1024-65.jpg",

"http://a3.mzstatic.com/us/r1000/036/Purple/cc/14/98/mzl.dyairego.1024x1024-65.jpg"

);

isGameCenterEnabled = 0;

kind = software;

languageCodesISO2A = (

EN

);

price = 0;

primaryGenreId = 6015;

primaryGenreName = Finance;

releaseDate = "2011-01-24T06:14:35Z";

releaseNotes = "* View Real-time streaming prices for U.S. Treasuries \n\n* Open and Save your Citi Research in your favorite PDF Reader and Library such as iBooks\n\n* Search for your favorite videos";

screenshotUrls = (

"http://a3.mzstatic.com/us/r1000/066/Purple/17/51/fb/mzl.zywiavgn.png",

"http://a5.mzstatic.com/us/r1000/026/Purple/73/85/97/mzl.csmdtndk.png"

);

sellerName = "Citibank, N.A.";

sellerUrl = "http://";

supportedDevices = (

all

);

trackCensoredName = "Citi Velocity";

trackContentRating = "4+";

trackId = 414697122;

trackName = "Citi Velocity";

trackViewUrl = "http://itunes.apple.com/us/app/citi-velocity/id414697122?mt=8&uo=4";

userRatingCount = 5;

userRatingCountForCurrentVersion = 1;

version = "1.4";

wrapperType = software;

}

);

}

然后从中取得 results 数组即可,具体代码如下所示:

NSDictionary *jsonData = [dataPayload JSONValue];

NSArray *infoArray = [jsonData objectForKey:@"results"];

NSDictionary *releaseInfo = [infoArray objectAtIndex:0];

NSString *latestVersion = [releaseInfo objectForKey:@"version"];

NSString *trackViewUrl = [releaseInfo objectForKey:@"trackViewUrl"];

如果你拷贝 trackViewUrl 的实际地址,然后在浏览器中打开,就会打开你的应用程序在 appstore 中的介绍页面。当然我们也可以在代码中调用 safari 来打开它。

UIApplication *application = [UIApplication sharedApplication];

[application openURL:[NSURL URLWithString:trackViewUrl]];

这是评论的地址:

在iPhone应用里直接打开app store 评论页面的方法:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=abc"]];

复制代码

更换下id号就可以。

如果想要打开下载页面,把url改为

itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=40461254

更换下id号就可以。

以上转自:http://blog.sina.com.cn/s/blog_7893e6970102vhe0.html





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值