根据bundle ID获取App Store的APP信息(可用来检测新版本,可以不考虑APP ID了)

首先,自问自答:

问:为什么不使用APP ID呢?

答:APP ID没有保存在 -info.plist 文件,不方便嘛。Bundle ID 保存在 -info.plist文件。

我要做通用性的功能,所以,查找时,以Bundle ID做搜索条件。


下面,搜索APP信息:

(1 ) 这是很重要的:

(千万要注意:下面的bundleId必须写成bundleId,不能写成 bundleid或者bundleID)

https://itunes.apple.com/lookup?bundleId=你APP的Bundle ID

(你也可以用http,不用https, 但是貌似最近http经常获取不到)



(2) 如果找到了,返回json格式的数据:

比如:

 
{
 "resultCount":1,
 "results": [
{"kind":"software", "features":[], 
"supportedDevices":["iPhone5s", "iPhone4", "iPadFourthGen", "iPadWifi", "iPadFourthGen4G", "iPodTouchourthGen", "iPad2Wifi", "iPhone4S", "iPadMini4G", "iPhone-3GS", "iPhone5", "iPodTouchFifthGen", "iPhone5c", "iPad3G", "iPadThirdGen4G", "iPadMini", "iPodTouchThirdGen", "iPadThirdGen", "iPad23G"], "isGameCenterEnabled":false, "screenshotUrls":["http://a2.mzstatic.com/us/r30/Purple6/v4/65/d9/f4/65d9f4c8-83aa-aedc-7d33-17bfcd95f329/screen1136x1136.jpeg"], "ipadScreenshotUrls":[], "artworkUrl60":"http://a637.phobos.apple.com/us/r30/Purple/v4/f9/c6/d2/f9c6d227-bab9-3008-88b6-ea74e48510a7/57.png", "artworkUrl512":"http://a157.phobos.apple.com/us/r30/Purple4/v4/c7/77/dd/c777dd5f-a1c2-e0fa-6a6f-1c4e3db98c12/mzl.tqbteywq.png", "artistViewUrl":"https://itunes.apple.com/us/artist/shenzhen-reecam-tech.-ltd./id479468962?uo=4", "artistId":479468962, "artistName":"Shenzhen Reecam Tech. Ltd.", "price":0.00, "version":"1.1.9", 
"description":"1, play video and audio via IP Camera \n2, it can directly access camera in LAN or internet \n3, get a snapshot from video and save it into the album \n4, search cameras in LAN \n5, it can control a camera via WIFI \n6, play video in full-screen \n7, reconnect to camera automaticly \n8, smart connection", "currency":"USD", "genres":["Business", "Photo & Video"], "genreIds":["6000", "6008"], "releaseDate":"2014-01-28T19:57:38Z", "sellerName":"Shen Zhen Rui Cai TECH.LTD", "bundleId":"net.reecam.uccamPush", "trackId":805363884, "trackName":"UCCAM.", "primaryGenreName":"Business", "primaryGenreId":6000, "releaseNotes":"(1) new notice interface\n(2) get alarm pictures when click  the \"OK\" button on notice interface", "formattedPrice":"Free", "wrapperType":"software", "trackCensoredName":"UCCAM.", "languageCodesISO2A":["EN", "ZH"], "fileSizeBytes":"16497902", "sellerUrl":"http://www.reecam.net", "contentAdvisoryRating":"4+", "artworkUrl100":"http://a157.phobos.apple.com/us/r30/Purple4/v4/c7/77/dd/c777dd5f-a1c2-e0fa-6a6f-1c4e3db98c12/mzl.tqbteywq.png", "trackViewUrl":"https://itunes.apple.com/us/app/uccam./id805363884?mt=8&uo=4", "trackContentRating":"4+"}]
}

版本号:找到那个"version",它的值就是版本号

URL:找到那个“trackViewUrl", 它的值就是介绍这个APP的链接网址

你可以对比本地APP的版本号和APP Store上发布的版本号,如果有新版本,可以提示用户要更新...


(3)如果没找到:

{
 "resultCount":0,
 "results": []
}


(4)这里顺便告诉大家用 JSONKit 取出版本号,

//注意:这里是示例,用阻塞操作,不考虑异常情况

//下面读取的是本地APP的Bundle ID:

NSString* bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString*) kCFBundleIdentifierKey];

NSString* strURL = [ NSString stringWithFormat:@"https://itunes.apple.com/lookup?bundleId=%@",bundleID ];

NSData* data = [ NSData dataWithContentsOfURL:[ NSURL URLWithString: strURL ]];

NSDictionary* dic = [data objectFromJSONData ];

NSArray* resultArray = [ dic objectForKey:@"results"];

NSDictionary* subDict = [resultArray objectAtIndex: 0 ];
NSString* strVersion = [subDict objectForKey: @"version"];

这个strVersion就是版本号啦


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用以下代码生成一个可以ping其他IP的安卓应用: ``` public class PingActivity extends Activity { private EditText mEditText; private TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ping); mEditText = (EditText) findViewById(R.id.editText); mTextView = (TextView) findViewById(R.id.textView); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String ip = mEditText.getText().toString(); if (TextUtils.isEmpty(ip)) { Toast.makeText(PingActivity.this, "请输入IP地址", Toast.LENGTH_SHORT).show(); return; } new PingTask().execute(ip); } }); } private class PingTask extends AsyncTask<String, Void, Boolean> { @Override protected Boolean doInBackground(String... params) { String ip = params[0]; try { Process process = Runtime.getRuntime().exec("/system/bin/ping -c 1 " + ip); int status = process.waitFor(); return status == 0; } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return false; } @Override protected void onPostExecute(Boolean result) { if (result) { mTextView.setText("Ping成功"); } else { mTextView.setText("Ping失败"); } } } } ``` 这个应用程序包含一个文本框和一个按钮。用户可以在文本框中输入要ping的IP地址,然后点击按钮来执行ping操作。应用程序使用Android的Runtime类来执行ping命令,并在执行完成后显示结果。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值