处理上架的问题
1:处理了openurl 拉起问题 2:去掉了http 3 隐私等等
This commit is contained in:
@@ -51,8 +51,6 @@
|
||||
|
||||
// 基础baseUrl
|
||||
#ifndef KB_BASE_URL
|
||||
//#define KB_BASE_URL @"https://m1.apifoxmock.com/m1/5438099-5113192-default/"
|
||||
//#define KB_BASE_URL @"http://192.168.2.22:7529/api"
|
||||
#define KB_BASE_URL @"https://devcallback.loveamorkey.com/api"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,11 +6,17 @@
|
||||
// 从扩展拉起主app
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <TargetConditionals.h>
|
||||
#if __has_include(<UIKit/UIKit.h>)
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
@class UIResponder;
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBHostAppLauncher : NSObject
|
||||
/// 从某个 responder 出发,尝试通过 UIApplication 打开宿主 app 的 URL
|
||||
/// 在主 App 内打开 URL。注意:在 App Extension 环境下会直接返回 NO(扩展内请使用 `extensionContext openURL:`)。
|
||||
+ (BOOL)openHostAppURL:(NSURL *)url fromResponder:(UIResponder *)startResponder;
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,46 +7,34 @@
|
||||
|
||||
// KBHostAppLauncher.m
|
||||
#import "KBHostAppLauncher.h"
|
||||
#import <objc/message.h>
|
||||
#import <TargetConditionals.h>
|
||||
#if !TARGET_OS_EXTENSION
|
||||
#import <UIKit/UIKit.h>
|
||||
#endif
|
||||
|
||||
@implementation KBHostAppLauncher
|
||||
|
||||
+ (BOOL)openHostAppURL:(NSURL *)url fromResponder:(UIResponder *)startResponder {
|
||||
if (!url || !startResponder) return NO;
|
||||
|
||||
UIResponder *responder = startResponder;
|
||||
while (responder) {
|
||||
if ([responder isKindOfClass:[UIApplication class]]) {
|
||||
UIApplication *app = (UIApplication *)responder;
|
||||
#if TARGET_OS_EXTENSION
|
||||
// App Extension 环境下禁止使用 UIApplication。
|
||||
return NO;
|
||||
#else
|
||||
// 在主 App 内直接通过 UIApplication 打开即可,不需要 responder 链绕行。
|
||||
UIApplication *app = UIApplication.sharedApplication;
|
||||
if (!app) { return NO; }
|
||||
|
||||
if (@available(iOS 18.0, *)) {
|
||||
// iOS 18+:用新的 open:options:completionHandler:
|
||||
SEL sel = @selector(openURL:options:completionHandler:);
|
||||
if ([app respondsToSelector:sel]) {
|
||||
// 等价于 [app openURL:url options:@{} completionHandler:nil];
|
||||
void (*func)(id, SEL, NSURL *, NSDictionary *, void(^)(BOOL)) = (void *)objc_msgSend;
|
||||
if (func) {
|
||||
func(app, sel, url, @{}, nil);
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
} else {
|
||||
// iOS 17-:兼容老的 openURL:
|
||||
if (@available(iOS 10.0, *)) {
|
||||
[app openURL:url options:@{} completionHandler:nil];
|
||||
return YES;
|
||||
} else {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if ([app respondsToSelector:@selector(openURL:)]) {
|
||||
return [app openURL:url];
|
||||
}
|
||||
return [app openURL:url];
|
||||
#pragma clang diagnostic pop
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
responder = responder.nextResponder;
|
||||
}
|
||||
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -6,7 +6,13 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifndef KB_MAI_POINT_BASE_URL
|
||||
#if DEBUG
|
||||
#define KB_MAI_POINT_BASE_URL @"http://192.168.2.21:35310/api"
|
||||
#else
|
||||
/// Release 默认关闭埋点上报(避免内网地址/HTTP 出现在上架包里)。
|
||||
/// 线上如需开启,请在 Build Settings(Preprocessor Macros)中覆盖该宏为 HTTPS 地址。
|
||||
#define KB_MAI_POINT_BASE_URL @""
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef KB_MAI_POINT_PATH_NEW_ACCOUNT
|
||||
|
||||
@@ -201,8 +201,19 @@ static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *base = [self kb_trimmedStringOrEmpty:KB_MAI_POINT_BASE_URL];
|
||||
if (base.length == 0) {
|
||||
// Release 默认关闭:避免上架包携带内网/HTTP 域名。
|
||||
if (completion) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion(YES, nil);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *safePath = [path hasPrefix:@"/"] ? path : [@"/" stringByAppendingString:path];
|
||||
NSString *urlString = [NSString stringWithFormat:@"%@%@", KB_MAI_POINT_BASE_URL, safePath];
|
||||
NSString *urlString = [NSString stringWithFormat:@"%@%@", base, safePath];
|
||||
NSURL *url = [NSURL URLWithString:urlString];
|
||||
if (!url) {
|
||||
NSError *error = [NSError errorWithDomain:KBMaiPointErrorDomain
|
||||
@@ -216,6 +227,18 @@ static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !DEBUG
|
||||
// 上架版本只允许 HTTPS,上报地址若为 HTTP 则视为关闭。
|
||||
if (![url.scheme.lowercaseString isEqualToString:@"https"]) {
|
||||
if (completion) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completion(YES, nil);
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
NSError *jsonError = nil;
|
||||
NSData *body = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&jsonError];
|
||||
if (jsonError) {
|
||||
|
||||
Reference in New Issue
Block a user