iphone/ipad应用的升级更新提醒和评分提醒

来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:44 点击:

在使用iphone/ipad应用的时候,有时候应用有更新升级,appstore会提醒用户有相应的更新,程序中需要在用户打开应用的时候提醒用户更新,那么就需要自己在程序当中写一个提醒事项,简历弹出框提醒用户一下,就ok了!

具体代码分享给大家,请大家注意,必须要有app的id。那么你会想应用第一次没有id怎么办?审请上线的时候就会得到id了,到时候有了id直接填上去就行了。


首先写一个单例类:

 

//
//  AppUpdateGrade.h
//  QingDaoBroadcastIpad
//
//  Created by iHope on 13-7-23.
//  Copyright (c) 2013年 hlren. All rights reserved.
//  任海丽

#import <Foundation/Foundation.h>

@interface AppUpdateGrade : NSObject
{
    NSString *appId; //app的id
    NSString *trackViewUrl; //app的地址
}
+(AppUpdateGrade*)sharedAppupdateGrade; //创建
-(void)appUpdate:(NSString *)appleID; //更新
-(void)appGrade:(NSString *)appleID; //评分

@end
//
//  AppUpdateGrade.m
//  QingDaoBroadcastIpad
//
//  Created by iHope on 13-7-23.
//  Copyright (c) 2013年 hlren. All rights reserved.
//

#import "AppUpdateGrade.h"

@implementation AppUpdateGrade

static AppUpdateGrade* appUpdateGrade = nil;
+(AppUpdateGrade*)sharedAppupdateGrade
{
    @synchronized(self)
    {
        if (appUpdateGrade == nil)
        {
            appUpdateGrade = [[self alloc] init];
        }
    }
    return appUpdateGrade;
}

//更新升级
-(void)appUpdate:(NSString *)appleID
{
    appId = appleID;
    //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=%@",appleID]]];
    // 设置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 *trackViewUrl1 = [releaseInfo objectForKey:@"trackViewUrl"];//地址trackViewUrl
        trackViewUrl = trackViewUrl1; //地址
        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) {
            
            UIAlertView *alert;
            alert = [[UIAlertView alloc] initWithTitle:@"app应用名称"
                                               message:@"有新版本,是否升级!"
                                              delegate: self
                                     cancelButtonTitle:@"取消"
                                     otherButtonTitles: @"升级", nil];
            alert.tag = 1001;
            [alert show];
        }
        
    }else{
        //无此应用
    }
    
}

//评分
-(void)appGrade:(NSString *)appleID{
    appId = appleID;
    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 = 1000;
        [alert show];
    }
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (alertView.tag) {
        case 1000:
        {
            //评分
            // 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 1001:
        {
            //升级            
            if (buttonIndex == 1) {
                NSLog(@"%@",trackViewUrl);
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];
                
            }
        }
            break;
        default:
            break;
    }
    
}
@end
	
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • Lexical or Preprocessor Issue 'xxx.h
  • ios学习笔记(二)xcode 4.3.2下实现基本交互
  • ios版本的helloworld
  • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
  • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
  • IOS类似iphone通讯录TableView的完整demo【附源码】
  • UITableView一些方法
  • [iPhone中级]iPhone团购信息客户端的开发 (二)
  • 如何为Iphone应用创建启动界面
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1