新增app更新弹窗

This commit is contained in:
2026-03-04 18:05:39 +08:00
parent 973577c6eb
commit 2d02e05956
7 changed files with 343 additions and 6 deletions

View File

@@ -26,6 +26,7 @@
#import "KBLoginVC.h"
#import "KBConfig.h"
#import "KBSkinInstallBridge.h"
#import "KBAppUpdateView.h"
static NSTimeInterval const kKBSubscriptionPrefillTTL = 10 * 60.0;
@@ -34,6 +35,10 @@ static NSTimeInterval const kKBSubscriptionPrefillTTL = 10 * 60.0;
// CustomKeyboard target com.loveKey.nyx.CustomKeyboard
//static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomKeyboard";
@interface AppDelegate () <KBAppUpdateViewDelegate>
@property (nonatomic, strong) LSTPopView *appUpdatePopView;
@end
@implementation AppDelegate
@@ -68,6 +73,8 @@ static NSTimeInterval const kKBSubscriptionPrefillTTL = 10 * 60.0;
//
[self kb_installDefaultSkinIfNeeded];
[self kb_requestAppUpdateAndPresentIfNeeded];
#if !DEBUG
/// Bugly
BuglyConfig *buglyConfig = [BuglyConfig new];
@@ -79,6 +86,34 @@ static NSTimeInterval const kKBSubscriptionPrefillTTL = 10 * 60.0;
return YES;
}
- (void)kb_requestAppUpdateAndPresentIfNeeded {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.appUpdatePopView) { return; }
CGFloat width = KBFit(323.0);
CGFloat height = KBFit(390.0);
KBAppUpdateView *view = [[KBAppUpdateView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
view.backgroundImageName = @"app_update_bg";
view.delegate = self;
LSTPopView *pop = [LSTPopView initWithCustomView:view
parentView:nil
popStyle:LSTPopStyleScale
dismissStyle:LSTDismissStyleScale];
pop.hemStyle = LSTHemStyleCenter;
pop.bgColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
pop.isClickBgDismiss = NO;
pop.cornerRadius = 0;
self.appUpdatePopView = pop;
[pop pop];
});
}
#pragma mark - KBAppUpdateViewDelegate
- (void)appUpdateViewDidTapUpgrade:(KBAppUpdateView *)view {
[self.appUpdatePopView dismiss];
self.appUpdatePopView = nil;
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
// [self kb_checkNetworkAndShowAlertIfNeeded];

View File

@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "app_update_bg@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "app_update_bg@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 KiB

View File

@@ -0,0 +1,30 @@
//
// KBAppUpdateView.h
// keyBoard
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class KBAppUpdateView;
@protocol KBAppUpdateViewDelegate <NSObject>
@optional
- (void)appUpdateViewDidTapUpgrade:(KBAppUpdateView *)view;
@end
@interface KBAppUpdateView : UIView
@property (nonatomic, weak) id<KBAppUpdateViewDelegate> delegate;
@property (nonatomic, copy) NSString *backgroundImageName;
@property (nonatomic, copy) NSString *titleText;
@property (nonatomic, copy) NSString *versionText;
@property (nonatomic, copy) NSString *contentTitleText;
@property (nonatomic, copy) NSArray<NSString *> *contentItems;
@property (nonatomic, copy) NSString *upgradeButtonTitle;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,244 @@
//
// KBAppUpdateView.m
// keyBoard
//
#import "KBAppUpdateView.h"
@interface KBAppUpdateView ()
@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIView *versionBadgeView;
@property (nonatomic, strong) UILabel *versionLabel;
@property (nonatomic, strong) UILabel *contentTitleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIButton *upgradeButton;
@end
@implementation KBAppUpdateView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
self.layer.cornerRadius = KBFit(22.0);
self.layer.masksToBounds = YES;
[self setupUI];
[self setupConstraints];
[self applyDefaultTexts];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
if (self = [super initWithCoder:coder]) {
self.backgroundColor = [UIColor whiteColor];
self.layer.cornerRadius = KBFit(22.0);
self.layer.masksToBounds = YES;
[self setupUI];
[self setupConstraints];
[self applyDefaultTexts];
}
return self;
}
#pragma mark - Setup
- (void)setupUI {
[self addSubview:self.backgroundImageView];
[self addSubview:self.titleLabel];
[self addSubview:self.versionBadgeView];
[self.versionBadgeView addSubview:self.versionLabel];
[self addSubview:self.contentTitleLabel];
[self addSubview:self.contentLabel];
[self addSubview:self.upgradeButton];
}
- (void)setupConstraints {
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(KBFit(45.0));
make.top.equalTo(self).offset(KBFit(70.0));
make.right.lessThanOrEqualTo(self).offset(-KBFit(24.0));
}];
[self.versionBadgeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(KBFit(45.0));
make.top.equalTo(self).offset(KBFit(120.0));
make.width.mas_equalTo(KBFit(73.0));
make.height.mas_equalTo(KBFit(23.0));
}];
[self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.versionBadgeView);
}];
[self.contentTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(KBFit(45.0));
make.top.equalTo(self).offset(KBFit(181.0));
make.right.lessThanOrEqualTo(self).offset(-KBFit(20.0));
}];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(KBFit(45.0));
make.top.equalTo(self.contentTitleLabel.mas_bottom).offset(KBFit(8.0));
make.right.lessThanOrEqualTo(self).offset(-KBFit(20.0));
make.bottom.lessThanOrEqualTo(self.upgradeButton.mas_top).offset(-KBFit(16.0));
}];
[self.upgradeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.bottom.equalTo(self).offset(-KBFit(12.0));
make.width.mas_equalTo(KBFit(230.0));
make.height.mas_equalTo(KBFit(45.0));
}];
}
- (void)applyDefaultTexts {
self.titleText = KBLocalized(@"");
self.versionText = @"V1.1.4";
self.contentTitleText = KBLocalized(@"Ver. Update Content");
self.contentItems = @[
KBLocalized(@"AAAAAAAAAAAAAAAAAAA"),
KBLocalized(@"SSSSSSSSSSSSSSSSSSS")
];
self.upgradeButtonTitle = KBLocalized(@"立即升级");
}
#pragma mark - Actions
- (void)onTapUpgrade {
if ([self.delegate respondsToSelector:@selector(appUpdateViewDidTapUpgrade:)]) {
[self.delegate appUpdateViewDidTapUpgrade:self];
}
}
#pragma mark - Setters
- (void)setBackgroundImageName:(NSString *)backgroundImageName {
_backgroundImageName = [backgroundImageName copy];
if (_backgroundImageName.length > 0) {
self.backgroundImageView.image = [UIImage imageNamed:_backgroundImageName];
} else {
self.backgroundImageView.image = nil;
}
}
- (void)setTitleText:(NSString *)titleText {
_titleText = [titleText copy];
self.titleLabel.text = _titleText;
}
- (void)setVersionText:(NSString *)versionText {
_versionText = [versionText copy];
self.versionLabel.text = _versionText;
}
- (void)setContentTitleText:(NSString *)contentTitleText {
_contentTitleText = [contentTitleText copy];
self.contentTitleLabel.text = _contentTitleText;
}
- (void)setContentItems:(NSArray<NSString *> *)contentItems {
_contentItems = [contentItems copy];
self.contentLabel.text = [self formattedContentItems:_contentItems];
}
- (void)setUpgradeButtonTitle:(NSString *)upgradeButtonTitle {
_upgradeButtonTitle = [upgradeButtonTitle copy];
[self.upgradeButton setTitle:_upgradeButtonTitle forState:UIControlStateNormal];
}
#pragma mark - Helpers
- (NSString *)formattedContentItems:(NSArray<NSString *> *)items {
if (items.count == 0) {
return @"";
}
NSMutableArray<NSString *> *lines = [NSMutableArray array];
[items enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
if (![obj isKindOfClass:[NSString class]] || obj.length == 0) {
return;
}
NSString *line = [NSString stringWithFormat:@"%lu、%@", (unsigned long)(idx + 1), obj];
[lines addObject:line];
}];
return [lines componentsJoinedByString:@"\n"];
}
#pragma mark - Lazy
- (UIImageView *)backgroundImageView {
if (!_backgroundImageView) {
_backgroundImageView = [[UIImageView alloc] init];
_backgroundImageView.contentMode = UIViewContentModeScaleAspectFill;
_backgroundImageView.clipsToBounds = YES;
}
return _backgroundImageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.numberOfLines = 0;
_titleLabel.font = [KBFont bold:26.0];
_titleLabel.textColor = [UIColor colorWithHex:0xF6FCFF];
}
return _titleLabel;
}
- (UIView *)versionBadgeView {
if (!_versionBadgeView) {
_versionBadgeView = [[UIView alloc] init];
_versionBadgeView.backgroundColor = [UIColor colorWithHex:0xFFDE67];
_versionBadgeView.layer.cornerRadius = KBFit(11.5);
_versionBadgeView.layer.masksToBounds = YES;
}
return _versionBadgeView;
}
- (UILabel *)versionLabel {
if (!_versionLabel) {
_versionLabel = [[UILabel alloc] init];
_versionLabel.font = [KBFont regular:14.0];
_versionLabel.textColor = [UIColor colorWithHex:0x3D3D3D];
_versionLabel.textAlignment = NSTextAlignmentCenter;
}
return _versionLabel;
}
- (UILabel *)contentTitleLabel {
if (!_contentTitleLabel) {
_contentTitleLabel = [[UILabel alloc] init];
_contentTitleLabel.font = [KBFont regular:18.0];
_contentTitleLabel.textColor = [UIColor colorWithHex:0x085E59];
}
return _contentTitleLabel;
}
- (UILabel *)contentLabel {
if (!_contentLabel) {
_contentLabel = [[UILabel alloc] init];
_contentLabel.numberOfLines = 0;
_contentLabel.font = [KBFont medium:13.0];
_contentLabel.textColor = [UIColor colorWithHex:0x085E59];
}
return _contentLabel;
}
- (UIButton *)upgradeButton {
if (!_upgradeButton) {
_upgradeButton = [UIButton buttonWithType:UIButtonTypeCustom];
_upgradeButton.backgroundColor = [UIColor colorWithHex:0x002339];
_upgradeButton.layer.cornerRadius = KBFit(22.5);
_upgradeButton.layer.masksToBounds = YES;
_upgradeButton.titleLabel.font = [KBFont bold:14.0];
[_upgradeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[_upgradeButton addTarget:self action:@selector(onTapUpgrade) forControlEvents:UIControlEventTouchUpInside];
}
return _upgradeButton;
}
@end