iOS 18适配问题记录(Xcode16正式版)

问题1:ADClient编译报错问题

报错信息

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_ADClient", referenced from:
       in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

相关代码(demo)

原因

苹果对AdClicent API加了一个标识
ADCLIENT_DEPRECATED_IOS_90_145_OBSOLETED_180
表示:iOS7.1-iOS14.5可用,iOS18彻底废弃,会在iOS18系统上编译失败。

解决办法

使用AdService库的AAAttribution替代,注意iOS14.3才可以使用。

代码

if (@available(ios 14.3, *)) {
        NSError *error;
        NSString *token = [AAAttribution attributionTokenWithError:&error];
        if (token != nil) {
            ...
        }
}

参考

https://developer.apple.com/forums/thread/759156
https://developer.apple.com/documentation/iad?language=objc

问题2:Xcode16(正式版)运行时,YYCache导致crash

报错信息

原因

在 iOS18 中,需要提前对 sqlite3_stmt 执行 sqlite3_finalize。

解决办法

代码

- (BOOL)_dbClose {
    if (!_db) return YES;
    
    int  result = 0;
    BOOL retry = NO;
    BOOL stmtFinalized = NO;
    
    if (@available(iOS 18, *)) {
        if (_dbStmtCache) {
            CFIndex size = CFDictionaryGetCount(_dbStmtCache);
            CFTypeRef *valuesRef = (CFTypeRef *)malloc(size * sizeof(CFTypeRef));
            CFDictionaryGetKeysAndValues(_dbStmtCache, NULL, (const void **)valuesRef);
            const sqlite3_stmt **stmts = (const sqlite3_stmt **)valuesRef;
            for (CFIndex i = 0; i < size; i ++) {
                sqlite3_stmt *stmt = stmts[i];
                sqlite3_finalize(stmt);
            }
            free(valuesRef);
            CFRelease(_dbStmtCache);
        }
    } else {
        if (_dbStmtCache) CFRelease(_dbStmtCache);
        _dbStmtCache = NULL;
    }
    
    do {
        retry = NO;
        result = sqlite3_close(_db);
        if (result == SQLITE_BUSY || result == SQLITE_LOCKED) {
            if (!stmtFinalized) {
                stmtFinalized = YES;
                sqlite3_stmt *stmt;
                while ((stmt = sqlite3_next_stmt(_db, nil)) != 0) {
                    sqlite3_finalize(stmt);
                    retry = YES;
                }
            }
        } else if (result != SQLITE_OK) {
            if (_errorLogsEnabled) {
                NSLog(@"%s line:%d sqlite close failed (%d).", __FUNCTION__, __LINE__, result);
            }
        }
    } while (retry);
    _db = NULL;
    return YES;
}

参考

https://giters.com/ibireme/YYCache/issues/166

问题3:Xcode16正式版,addSubView crash (maskView)

报错信息

image.png
*** Assertion failure in -[TestMaskView _addSubview:positioned:relativeTo:], UIView.m:18496
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Set `maskView` (<UIView: 0x14a21ddd0; frame = (0 0; 0 0); layer = <CALayer: 0x60000314b480>>) to `nil` before adding it as a subview of <TestMaskView: 0x153e08350; frame = (0 0; 393 852); layer = <CALayer: 0x60000314b440>>'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001063540ec __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00000001048bede8 objc_exception_throw + 72
    2   Foundation                          0x0000000109d21aa8 _userInfoForFileAndLine + 0
    3   UIKitCore                           0x0000000128c0151c -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1124
    4   ADClientTest                        0x0000000104609660 -[TestMaskView initWithFrame:] + 276
    5   ADClientTest                        0x0000000104609434 -[ViewController viewDidLoad] + 164
    6   UIKitCore                           0x0000000127f1e69c -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 80
    7   UIKitCore                           0x0000000127f23238 -[UIViewController loadViewIfRequired] + 908
    8   UIKitCore                           0x0000000127f234e0 -[UIViewController view] + 20
    9   UIKitCore                           0x00000001286c3a08 -[UIWindow addRootViewControllerViewIfPossible] + 132
    10  UIKitCore                           0x00000001286c343c -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 168
    11  UIKitCore                           0x00000001286c4288 -[UIWindow _setHidden:forced:] + 228
    12  UIKitCore                           0x00000001286d3344 -[UIWindow _mainQueue_makeKeyAndVisible] + 36
    13  UIKitCore                           0x000000012892dcd8 -[UIWindowScene _performDeferredInitialWindowUpdateForConnection] + 204
    14  UIKitCore                           0x0000000127af58f0 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1164
    15  UIKitCore                           0x000000012868f45c -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 808
    16  UIKitCore                           0x000000012868f70c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 304
    17  UIKitCore                           0x000000012815ec08 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 260
    18  FrontBoardServices                  0x0000000113090ce4 __95-[FBSScene _callOutQueue_didCreateWithTransitionContext:alternativeCreationCallout:completion:]_block_invoke + 260
    19  FrontBoardServices                  0x00000001130910a4 -[FBSScene _callOutQueue_coalesceClientSettingsUpdates:] + 60
    20  FrontBoardServices                  0x0000000113090b64 -[FBSScene _callOutQueue_didCreateWithTransitionContext:alternativeCreationCallout:completion:] + 408
    21  FrontBoardServices                  0x00000001130bdd50 __93-[FBSWorkspaceScenesClient _callOutQueue_sendDidCreateForScene:transitionContext:completion:]_block_invoke.156 + 216
    22  FrontBoardServices                  0x000000011309d618 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 160
    23  FrontBoardServices                  0x00000001130bc220 -[FBSWorkspaceScenesClient _callOutQueue_sendDidCreateForScene:transitionContext:completion:] + 388
    24  libdispatch.dylib                   0x000000010bdea7b8 _dispatch_client_callout + 16
    25  libdispatch.dylib                   0x000000010bdee3bc _dispatch_block_invoke_direct + 388
    26  FrontBoardServices                  0x00000001130e0b58 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 44
    27  FrontBoardServices                  0x00000001130e0a34 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 196
    28  FrontBoardServices                  0x00000001130e0b8c -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 24
    29  CoreFoundation                      0x00000001062b8324 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    30  CoreFoundation                      0x00000001062b826c __CFRunLoopDoSource0 + 172
    31  CoreFoundation                      0x00000001062b7a2c __CFRunLoopDoSources0 + 324
    32  CoreFoundation                      0x00000001062b20b0 __CFRunLoopRun + 788
    33  CoreFoundation                      0x00000001062b1960 CFRunLoopRunSpecific + 536
    34  GraphicsServices                    0x0000000117edfb10 GSEventRunModal + 160
    35  UIKitCore                           0x000000012868db40 -[UIApplication _run] + 796
    36  UIKitCore                           0x0000000128691d38 UIApplicationMain + 124
    37  ADClientTest                        0x0000000104609064 main + 140
    38  dyld                                0x00000001047cd410 start_sim + 20
    39  ???                                 0x000000010490a274 0x0 + 4371554932
)
libc++abi: terminating due to uncaught exception of type NSException

原因

iOS 18 对 UIView的maskView 增加了断言,导致如果业务代码里有同名属性可能导致触发该断言。

经测试发现:
1.自定义UIView子视图,存在同名属性maskView,会崩溃
2.自定义cell,添加到cell视图上会崩溃,添加到contentView上,则不会崩溃
3.控制器里的maskView视图属性,添加到控制器view,不会崩溃

解决办法

修改自定义视图,将自定义子组件名为maskView的视图进行重命名。

参考

https://github.com/Tencent/QMUI_iOS/issues/1557

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 230,622评论 6 544
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 99,716评论 3 429
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 178,746评论 0 383
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 63,991评论 1 318
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 72,706评论 6 413
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 56,036评论 1 329
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 44,029评论 3 450
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 43,203评论 0 290
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 49,725评论 1 336
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 41,451评论 3 361
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 43,677评论 1 374
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 39,161评论 5 365
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 44,857评论 3 351
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 35,266评论 0 28
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 36,606评论 1 295
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 52,407评论 3 400
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 48,643评论 2 380

推荐阅读更多精彩内容