|
@@ -1,16 +1,38 @@
|
|
|
|
|
+import { native } from 'cc';
|
|
|
import { PlatformBridge } from './PlatformBridge';
|
|
import { PlatformBridge } from './PlatformBridge';
|
|
|
import { PlatformType } from './PlatformBridge';
|
|
import { PlatformType } from './PlatformBridge';
|
|
|
|
|
|
|
|
export class IOSPlatformBridge extends PlatformBridge {
|
|
export class IOSPlatformBridge extends PlatformBridge {
|
|
|
readonly type = PlatformType.IOS;
|
|
readonly type = PlatformType.IOS;
|
|
|
|
|
+ private _deviceID: string | null = null;
|
|
|
|
|
|
|
|
getUrlParam(_name: string): string | null {
|
|
getUrlParam(_name: string): string | null {
|
|
|
console.error('[IOS] 获取深度链接参数能力未实现');
|
|
console.error('[IOS] 获取深度链接参数能力未实现');
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** IDFV:同一开发商范围内的设备标识,不保证卸载重装后保持不变。 */
|
|
|
getDeviceID(): string | null {
|
|
getDeviceID(): string | null {
|
|
|
- console.error('[IOS] 获取设备号的能力未实现');
|
|
|
|
|
- return '';
|
|
|
|
|
|
|
+ if (this._deviceID) return this._deviceID;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // Creator 3.8 的声明只有 Android 签名;iOS 无参 selector 只传类名和方法名。
|
|
|
|
|
+ const iosReflection = native.reflection as unknown as {
|
|
|
|
|
+ callStaticMethod(className: string, methodName: string): unknown;
|
|
|
|
|
+ };
|
|
|
|
|
+ const deviceID = iosReflection.callStaticMethod(
|
|
|
|
|
+ 'CocosIOSPlatformBridge',
|
|
|
|
|
+ 'getDeviceID',
|
|
|
|
|
+ );
|
|
|
|
|
+ if (typeof deviceID === 'string' && deviceID.trim().length > 0) {
|
|
|
|
|
+ this._deviceID = deviceID.trim();
|
|
|
|
|
+ return this._deviceID;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('[IOS] 获取 IDFV 失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // IDFV 在设备重启后首次解锁前可能不可用;不缓存失败,下次调用重试。
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|