| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import { native } from 'cc';
- import { PlatformBridge } from './PlatformBridge';
- import { PlatformType } from './PlatformBridge';
- export class IOSPlatformBridge extends PlatformBridge {
- readonly type = PlatformType.IOS;
- private _deviceID: string | null = null;
- getUrlParam(_name: string): string | null {
- console.error('[IOS] 获取深度链接参数能力未实现');
- return null;
- }
- /** IDFV:同一开发商范围内的设备标识,不保证卸载重装后保持不变。 */
- getDeviceID(): string | null {
- 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;
- }
- }
|