1
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#import "KBHUD.h" // 复用 App 内的 HUD 封装
|
#import "KBHUD.h" // 复用 App 内的 HUD 封装
|
||||||
#import "KBLocalizationManager.h" // 复用多语言封装(可在扩展内使用)
|
#import "KBLocalizationManager.h" // 复用多语言封装(可在扩展内使用)
|
||||||
#import "KBMaiPointReporter.h"
|
#import "KBMaiPointReporter.h"
|
||||||
|
//#import "KBLog.h"
|
||||||
|
|
||||||
|
|
||||||
// 通用链接(Universal Links)统一配置
|
// 通用链接(Universal Links)统一配置
|
||||||
|
|||||||
20
Shared/KBLog.h
Normal file
20
Shared/KBLog.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// KBLog.h
|
||||||
|
// Shared debug logging macro (App + Extension)
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#ifndef KBLOG
|
||||||
|
// 调试专用日志(DEBUG 打印,RELEASE 不打印)。尽量显眼,包含函数与行号。
|
||||||
|
#if DEBUG
|
||||||
|
#define KBLOG(fmt, ...) do { \
|
||||||
|
NSString *kb_msg__ = [NSString stringWithFormat:(fmt), ##__VA_ARGS__]; \
|
||||||
|
NSString *kb_full_msg__ = [NSString stringWithFormat:@"\n==============================[KB DEBUG]==============================\n[Function] %s\n[Line] %d\n%@\n=====================================================================\n", __PRETTY_FUNCTION__, __LINE__, kb_msg__]; \
|
||||||
|
fprintf(stderr, "%s", kb_full_msg__.UTF8String); \
|
||||||
|
} while(0)
|
||||||
|
#else
|
||||||
|
#define KBLOG(...)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#ifndef KB_MAI_POINT_BASE_URL
|
#ifndef KB_MAI_POINT_BASE_URL
|
||||||
#define KB_MAI_POINT_BASE_URL @"http://192.168.1.188:35310/api"
|
#define KB_MAI_POINT_BASE_URL @"http://192.168.2.188:35310/api"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KB_MAI_POINT_PATH_NEW_ACCOUNT
|
#ifndef KB_MAI_POINT_PATH_NEW_ACCOUNT
|
||||||
|
|||||||
@@ -4,9 +4,33 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "KBMaiPointReporter.h"
|
#import "KBMaiPointReporter.h"
|
||||||
|
#import "KBLog.h"
|
||||||
|
|
||||||
NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
static void KBMaiPoint_DebugLogURL(NSURLRequest *request) {
|
||||||
|
NSString *url = request.URL.absoluteString ?: @"";
|
||||||
|
KBLOG(@"🍃[KBMaiPointReporter] url=%@", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void KBMaiPoint_DebugLogError(NSURLResponse *response, NSError *error) {
|
||||||
|
if (error) {
|
||||||
|
NSString *msg = error.localizedDescription ?: @"(no description)";
|
||||||
|
KBLOG(@"🍃[KBMaiPointReporter] error=%@ domain=%@ code=%ld", msg, error.domain ?: @"", (long)error.code);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ([response isKindOfClass:NSHTTPURLResponse.class]) {
|
||||||
|
NSInteger statusCode = ((NSHTTPURLResponse *)response).statusCode;
|
||||||
|
if (statusCode >= 200 && statusCode < 300) {
|
||||||
|
KBLOG(@"🍃[KBMaiPointReporter] status=HTTP_%ld", (long)statusCode);
|
||||||
|
} else {
|
||||||
|
KBLOG(@"🍃[KBMaiPointReporter] error=HTTP_%ld", (long)statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@implementation KBMaiPointReporter
|
@implementation KBMaiPointReporter
|
||||||
|
|
||||||
+ (instancetype)sharedReporter {
|
+ (instancetype)sharedReporter {
|
||||||
@@ -89,6 +113,10 @@ NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
|||||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||||
request.HTTPBody = body;
|
request.HTTPBody = body;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
KBMaiPoint_DebugLogURL(request);
|
||||||
|
#endif
|
||||||
|
|
||||||
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||||
config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
config.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
|
||||||
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
|
NSURLSession *session = [NSURLSession sessionWithConfiguration:config];
|
||||||
@@ -115,6 +143,10 @@ NSString * const KBMaiPointErrorDomain = @"KBMaiPointErrorDomain";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
KBMaiPoint_DebugLogError(response, finalError);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (completion) {
|
if (completion) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
completion(success, finalError);
|
completion(success, finalError);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
//-----------------------------------------------宏定义全局----------------------------------------------------------/
|
//-----------------------------------------------宏定义全局----------------------------------------------------------/
|
||||||
// 调试专用日志(DEBUG 打印,RELEASE 不打印)。尽量显眼,包含函数与行号。
|
// 调试专用日志(DEBUG 打印,RELEASE 不打印)。尽量显眼,包含函数与行号。
|
||||||
|
#ifndef KBLOG
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
#define KBLOG(fmt, ...) do { \
|
#define KBLOG(fmt, ...) do { \
|
||||||
NSString *kb_msg__ = [NSString stringWithFormat:(fmt), ##__VA_ARGS__]; \
|
NSString *kb_msg__ = [NSString stringWithFormat:(fmt), ##__VA_ARGS__]; \
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
#else
|
#else
|
||||||
#define KBLOG(...)
|
#define KBLOG(...)
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// 通用链接(Universal Links)统一配置
|
// 通用链接(Universal Links)统一配置
|
||||||
// 仅需修改这里的域名/前缀,工程内所有使用 UL 的地方都会同步。
|
// 仅需修改这里的域名/前缀,工程内所有使用 UL 的地方都会同步。
|
||||||
|
|||||||
Reference in New Issue
Block a user