蒲公英提示更新版本

一般公司用蒲公英来托管测试版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"]]];

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.ios高性能编程 (1).内层 最小的内层平均值和峰值(2).耗电量 高效的算法和数据结构(3).初始化时...
    欧辰_OSR阅读 30,468评论 8赞 265
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,858评论 1赞 32
  • 蒲公英官网 iOS篇 分发前需要有已打包ipa文件,打包详见《Xamarin 开发文档》 在蒲公英平台:https...
    pruple_Boy阅读 2,027评论 0赞 1
  • “你说过待这场兵戎结束,就会来娶我,战场上的你,一切都安好吧。” 她站在庭院之中,清澈的眸子里带着一丝情愁。她抬头...
    李什么废白阅读 177评论 0赞 0
  • 我遇到她那年,我24,她25。她万绿丛中过,片叶不沾身,她没有跟任何男孩深入交往过。 事实上,她个子不高,形貌平平...
    桐宸阅读 541评论 0赞 1

友情链接更多精彩内容