問題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)
相關(guān)代碼(demo)
原因
蘋果對AdClicent API加了一個標(biāo)識
ADCLIENT_DEPRECATED_IOS_90_145_OBSOLETED_180
表示:iOS7.1-iOS14.5可用,iOS18徹底廢棄简肴,會在iOS18系統(tǒng)上編譯失敗唯欣。
解決辦法
使用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(正式版)運(yùn)行時此疹,YYCache導(dǎo)致crash
報錯信息
原因
在 iOS18 中燃领,需要提前對 sqlite3_stmt 執(zhí)行 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)
報錯信息
*** 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 增加了斷言猛蔽,導(dǎo)致如果業(yè)務(wù)代碼里有同名屬性可能導(dǎo)致觸發(fā)該斷言剥悟。
經(jīng)測試發(fā)現(xiàn):
1.自定義UIView子視圖,存在同名屬性maskView曼库,會崩潰
2.自定義cell区岗,添加到cell視圖上會崩潰毁枯,添加到contentView上,則不會崩潰
3.控制器里的maskView視圖屬性种玛,添加到控制器view,不會崩潰
解決辦法
修改自定義視圖蒂誉,將自定義子組件名為maskView的視圖進(jìn)行重命名。