美文网首页
蒲公英提示更新版本

蒲公英提示更新版本

作者: 心情的蛊惑 | 来源:发表于2018-11-23 15:55 被阅读149次

一般公司用蒲公英来托管测试版app,而我们公司就是不一般,要把企业app放到蒲公英,活活浪费了企业账号的优势啊。

然后就开始了我的蒲公英的自动更新之路。

首先,我们要先到蒲公英的官网下载sdk。
1,通过cocopods安装framework

pod 'Pgyer'
pod 'PgyUpdate'

2,在项目的AppDelegate.m文件中引入头文件:

import <PgySDK/PgyManager.h>

import <PgyUpdate/PgyUpdateManager.h>

在application:didFinishLaunchingWithOptions 中调用 SDK:

//启动基本SDK
[[PgyManager sharedPgyManager] startManagerWithAppId:@"PGY_APP_ID"];
//启动更新检查SDK
[[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"PGY_APP_ID"];
其中PGY_APP_ID即在蒲公英上获取的App Key。

3,检查更新

在需要检查更新的文件中引入头文件:

import <PgyUpdate/PgyUpdateManager.h>

如果是使用蒲公英自动检测
然后调用

[[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"PGY_APP_ID"]; // 请将 PGY_APP_ID 换成应用的 App Key
[[PgyUpdateManager sharedPgyManager] checkUpdate];

这里我用的是自定义方法
[[PgyUpdateManager sharedPgyManager] checkUpdateWithDelegete:self selector:@selector(updateMethod)];
其中updateMethod为检查更新的回调方法。如果有新版本,则包含新版本信息的字典会被回传,否则字典为nil。如果想更新新版本,可通过调用

//蒲公英应用api_Key
#define VERSION_API_KEY @"db78fe9e7698d9bb13c1df9a39b24e7b"
//蒲公英应用User_Key
#define VERSION_User_Key @"ab5b16eca517abcbdb170e1dd87f4504"
//蒲公英应用App_Key
#define PGY_APP_ID @"ffab7b92ad25019d02eda36556640540"
//蒲公英应用页面地址后缀
#define VERSION_Shortcut @"sylibt"
//蒲公英应用itms-services下载
#define VERSION_Itms_Services @"itms-services://?action=download-manifest&url=https%3A%2F%2Fwww.pgyer.com%2Fapiv2%2Fapp%2Fplist%3FappKey%3Dffab7b92ad25019d02eda36556640540%26_api_key%3Ddb78fe9e7698d9bb13c1df9a39b24e7b"



dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSDictionary *dict = @{
                               @"_api_key" : VERSION_API_KEY,
                               @"buildShortcutUrl" : VERSION_Shortcut //应用页面地址后缀
                               };
        
        
        NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:VERSION_HTTPS_SERVER parameters:dict error:nil];
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
//        MJWeakSelf
        NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
            if (error) {
                NSLog(@"Error: %@", error);
                return;
            }
            SYLog(@"%@ %@", response, responseObject);
            if ([[responseObject valueForKey:@"code"] intValue] == 0) {
                SYLog(@"CDDMall请求成功 appVersion%@,appVersionNo%@",[[responseObject valueForKey:@"data"] valueForKey:@"appVersion"],[[responseObject valueForKey:@"data"] valueForKey:@"appVersionNo"]);
                
                //是否是最新版
//                NSInteger buildIsLastest = [[responseObject valueForKey:@"data"]
//                                            valueForKey:@"buildIsLastest"];
                NSString *newVersion = [[responseObject valueForKey:@"data"] valueForKey:@"buildVersion"];
//                NSString *newBiuld = [[responseObject valueForKey:@"data"] valueForKey:@"buildBuildVersion"];//为@""之前未上传过版本
                //获取本地的版本信息
                NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary];
                NSString *currentVersion = bundleInfo[@"CFBundleShortVersionString"];
//                NSString *currentBulid = bundleInfo[@"CFBundleVersion"];
                //                NSString *beforeVersion = BIULD_VERSION;
                //                NSString *beforeBiuld = BUNDLE_VERSION;
//                SYLog(@"%@----%@--%ld" , newVersion ,newBiuld ,buildIsLastest);
                if([newVersion compare:currentVersion options:NSCaseInsensitiveSearch] == NSOrderedDescending) {
                    SYProjectUpDate *update = [SYProjectUpDate sharedUpdate];
                    update.message =[[responseObject valueForKey:@"data"] valueForKey:@"buildUpdateDescription"];
                    [update alertUpdateForVersion:newVersion withForce:YES isMandatory:YES isPGY:YES];
                }
            }
            
        }];
        [dataTask resume];
    });

在要点更新的地方调用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:response[@"downloadURL"]]];

相关文章

  • 蒲公英提示更新版本

    一般公司用蒲公英来托管测试版app,而我们公司就是不一般,要把企业app放到蒲公英,活活浪费了企业账号的优势啊。 ...

  • 无标题文章

    //提示版本更新 [self VersonUpdate]; #pragma mark ------提示用户版本更新...

  • [版本更新提示]

    -(void)checkVersion { //每天进行一次版本判断 NSDateFormatter *forma...

  • 版本更新提示

  • 菜鸟教程——实现一句代码实现app更新检测

    版本更新提示是app必备功能,它可以有效提示用户更新。常用的更新提示无非有两种。一种是从苹果api获取版本信息,提...

  • iOS版本更新提示

    iOS更新提示比较简单,不需要后台记录版本号,直接去App Store获取最新版本即可。

  • 提示app 版本更新

    开发中我们可能会遇到这样的需求,当AppStore中有新版本迭代更新,在用户点开APP的时候弹框提醒客户去AppS...

  • app提示版本更新

    下面的 sender[@"version"] 就是获取的版本号 注意是String类型的 2 . 比较appSto...

  • APP版本更新提示

    本文将针对APP新版本提示为大家介绍两种方法,第一种方法是针对已将上线的APP,第二种针对没有上线的APP. 方式...

  • iOS 版本更新提示

    项目需求:由于公司项目是做离线地图的,老板希望有版本更新时用户能及时更新,所以要求app第一次检测到版本更新时记录...

网友评论

      本文标题:蒲公英提示更新版本

      本文链接:https://www.haomeiwen.com/subject/lzkafqtx.html