MacOS 开发 — 软件内部检测App Store 更新

本文介绍了一种在MacOS应用中检测AppStore更新的方法,通过AppStoreUpdateKit库实现应用内部更新检查,提供自定义UI及国际化支持,演示了如何检查新版本、定制更新提示及处理用户反馈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MacOS 开发 — 软件内部检测App Store 更新

https://github.com/JHiroGuo/AppStoreUpdateKit
在这里插入图片描述

如何安装

克隆仓库到本地,将AppStoreUpdateKit工程加入到你的项目。

功能

  • 根据你的需要进行自定义。
  • 检查Mac App Store的更新。
  • 非常好看的UI来请求用户进行更新或者跳过更新。

栗子

在工程文件里,编译执行’AppStoreUpdateKitDemo’这个目标程序,方可见demo.

参考文档

https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/LookupExamples.html

在这里插入图片描述

如何使用

  • 检查新版本是否可用
#import <AppStoreUpdateKit/AppStoreUpdateKit.h>

//Create an app object with your app info. (the productID is important, find the productID on itunes website, eg: https://itunes.apple.com/us/app/kaka/id1434172933?mt=12)

  AppStoreUpdateAppObject *appObj = [[AppStoreUpdateAppObject alloc]
                                       initWithAppName:@"UP Studio"
                                       withAppIcon:[NSImage imageNamed:@"up"]
                                       withCurrentVersion:@"1.0.11"
                                       withProductID:@"1119477741"];
//Synchronize to check app update.
    //rslt will be YES if getting app info is successful.
    BOOL rslt =[[AppStoreUpdateManager sharedManager] checkAppUpdate:appObj];
    //Check if new version is available.
    rslt = [appObj isNewVersionAvailable]
    
//Asynchronize to check app update.
    [[AppStoreUpdateManager sharedManager] checkAppUpdateAsync:appObj withCompletionBlock:^(BOOL rslt, AppStoreUpdateAppObject * _Nonnull AppObj) {
        //rslt will be YES if getting app info is successful.
        
        //Check if new version is available.
        rslt = [AppObj isNewVersionAvailable]
        
        //Your code here
    }];

  • 定制更新提示窗口
    //创建一个配置UI对象并且设定对应的值
AppStoreUpdateUIConfigure *UIConfigure = [[AppStoreUpdateUIConfigure alloc] init];
    [UIConfigure setSkipButtonTitle:@"跳过"];
    [UIConfigure setUpdateButtonTitle:@"更新"];
    [UIConfigure setLaterButtonTitle:@"稍后"];
    [UIConfigure setVersionText:@"版本 %@"];
    [UIConfigure setReleaseNotesText:@"更新说明:\n\n"];
    [UIConfigure setReleaseNotesNoneText:@"更新说明:\n\n 无"];
    
    //将UI配置对象传递给AppStoreUpdateManager
    [[AppStoreUpdateManager sharedManager] customize:UIConfigure];
  • 设置返回文案的语言
 //Only in Chinese and English, other can supplement
 [[AppStoreUpdateManager sharedManager] isInternationalAddress:YES];

-(void)isInternationalAddress:(BOOL)bInter
{
    if(bInter)
    {
        strRequest = @"https://itunes.apple.com/lookup?id=";
    }else
    {
        strRequest = @"https://itunes.apple.com/cn/lookup?id=";
    }
}
  • 跳过当前版本

//Check if the current new version has been skipped 
    [[AppStoreUpdateManager sharedManager] isCurrentNewVersionSkipped:appObj]
    
//Skip the current new version
    [[AppStoreUpdateManager sharedManager] skipCurrentNewVersion:AppObj];
      
  • 请求升级提示窗口并处理用户的返回结果
//This method MUST be invoked in the main thread!!
    [[AppStoreUpdateManager sharedManager] requestAppUpdateWindow:appObj withCompletionCallback:^(AppUpdateWindowResult rslt, AppStoreUpdateAppObject * _Nonnull AppObj) {
                    switch (rslt) {
                        case AppUpdateWindowResultUpdate:
                            [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"macappstore://itunes.apple.com/app/id%@",[AppObj productID]]]];
                            break;
                            
                        case AppUpdateWindowResultSkip:
                            [[AppStoreUpdateManager sharedManager] skipCurrentNewVersion:AppObj];
                            break;
                            
                        case AppUpdateWindowResultLater:
                            break;
                            
                        default:
                            break;
                    }
                }];

国家简称:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值