ios应用的升级更新提醒和评分提醒
来源:互联网 发布:美的和格力空调 知乎 编辑:程序博客网 时间:2024/05/29 03:26
直接上代码:
AppVersionManage.h
//// AppVersionManage.h// textNav//// Created by wxxu on 14/12/18.// Copyright (c) 2014年 wxxu. All rights reserved.// app版本管理#import <Foundation/Foundation.h>@interface AppVersionManage : NSObject+ (AppVersionManage *)sharedAppVersionManage;- (void)appUpdate:(NSString *)appId; //更新- (void)appScore:(NSString *)appid; //评分@end
AppVersionManage.m
//// AppVersionManage.m// textNav//// Created by wxxu on 14/12/18.// Copyright (c) 2014年 wxxu. All rights reserved.//#import <UIKit/UIKit.h>#import "AppVersionManage.h"@implementation AppVersionManage{ NSString *_appId; //app的id NSString *_trackViewUrl; //app的地址}static AppVersionManage *appVersionManage;+ (AppVersionManage *)sharedAppVersionManage{ @synchronized(self) { if (appVersionManage == nil) { appVersionManage = [[self alloc] init]; } return appVersionManage; }}#pragma mark 升级- (void)appUpdate:(NSString *)appId{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ _appId = appId; //http://itunes.apple.com/lookup?id=xx //根据appid从苹果服务器上得到json数据,再从json数据中得到版本信息 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; // 设置URL [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",_appId]]]; // 设置HTTP方法 [request setHTTPMethod:@"GET"]; // 发送同步請求, 這裡得returnData就是返回得數據楽 NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil]; // NSLog(@"%@",jsonData); NSArray *infoArray = [jsonData objectForKey:@"results"]; if (infoArray.count != 0) { NSDictionary *releaseInfo = [infoArray objectAtIndex:0]; NSString *latestVersion = [releaseInfo objectForKey:@"version"]; NSString *trackViewUrl = [releaseInfo objectForKey:@"trackViewUrl"];//地址trackViewUrl _trackViewUrl = trackViewUrl; //地址 double doubleUpdateVersion = [latestVersion doubleValue]; //获取当前version版本信息 //当前运行程序的版本信息,可以在 mainBundle 里面获取: NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"]; double doubleCurrentVersion = [currentVersion doubleValue]; NSLog(@"doubleCurrentVersion:%f,%f",doubleCurrentVersion,doubleUpdateVersion); if (doubleCurrentVersion < doubleUpdateVersion) { dispatch_async(dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"app应用名称" message:@"有新版本,是否升级!" delegate: self cancelButtonTitle:@"取消" otherButtonTitles: @"升级", nil]; alert.tag = 20141; [alert show]; }); } }else{ //无此应用 } });}#pragma mark 评分- (void)appScore:(NSString *)appid{ _appId = appid; BOOL neverGrade = [[[NSUserDefaults standardUserDefaults] objectForKey:@"neverGrade"] boolValue]; if(neverGrade != YES) { //提醒评分 UIAlertView *alert; alert = [[UIAlertView alloc] initWithTitle:@"app应用名称" message:@"请去appstore给我们评分" delegate: self cancelButtonTitle:@"取消" otherButtonTitles: @"现在去",@"不再提醒 ", nil]; alert.tag = 20142; [alert show]; }}#pragma mark 升级 评分点击-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == alertView.cancelButtonIndex) return; switch (alertView.tag) { case 20142: { //评分 // Never Review Button if (buttonIndex == 2) { NSString *number = [NSString stringWithFormat:@"%d", YES]; [[NSUserDefaults standardUserDefaults] setObject:number forKey:@"neverGrade"]; [[NSUserDefaults standardUserDefaults] synchronize]; } // Review Button else if (buttonIndex == 1) { NSString *number = [NSString stringWithFormat:@"%d", YES]; [[NSUserDefaults standardUserDefaults] setObject:number forKey:@"neverGrade"]; [[NSUserDefaults standardUserDefaults] synchronize]; //"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id= NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", _appId ]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; } } break; case 20141: { //升级 if (buttonIndex == 1) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_trackViewUrl]]; } } break; default: break; } }@end
代码下载地址:点击打开链接
1 0
- ios应用的升级更新提醒和评分提醒
- iphone/ipad应用的升级更新提醒和评分提醒
- iphone/ipad应用的升级更新提醒和评分提醒
- iphone/ipad应用的升级更新提醒和评分提醒
- iphone/ipad应用的升级更新提醒和评分提醒
- iOS客户端的升级提醒
- iOS 的更新提醒教程
- iOS 开发:应用内实现 更新提醒
- 改进iOS客户端的升级提醒功能
- 改进iOS客户端的升级提醒功能
- 改进iOS客户端的升级提醒功能
- 改进iOS客户端的升级提醒功能
- iOS应用版本更新(自动提醒用户更新代码)
- 版本的更新提醒
- iOS 每天提醒和每周提醒
- iOS 每天提醒和每周提醒
- 如何提醒用户更新应用?
- iOS开发 版本更新提醒
- 【LOL盒子】英雄详情->配音->【下载】与【播放】模块
- 内存溢出和内存泄漏的区别
- How to stop a Thread(怎样停止一个线程)
- 几个有用的python链接
- 第一篇博客
- ios应用的升级更新提醒和评分提醒
- Android数据的存储方式(1)SharedPreferences
- 类似评论、点评的JS标签选择功能(及jq动态绑定事件)
- FPGA学习网站
- 删除文件夹下所有的文件
- Solaris scp Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive)
- 使用JDBC连接SQL Server数据库
- 二叉树的建立和遍历
- 黑马程序员——Java语言基础——04.多线程(2)线程间通信