OGeek|极客世界-中国程序员成长平台

标题: c# - Unity中的Apple idfa通过插件 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:13
标题: c# - Unity中的Apple idfa通过插件

我从另一个堆栈溢出答案中借用了这段代码:

example.mm

const char* getIdfa()
{
    if([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled])
    {
        NSString * idfa = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
        //return (const char*)[idfa UTF8String]; // ##### malloc error I uncomment this line #####
    }
    return nil;
}

iOSplugin.cs

#if UNITY_IOS
    [DllImport("__Internal")]
    public static extern string getIdfa();
#endif

可能影响问题的 Xcode build设置: 项目格式:兼容xcode 3.1 Obj-C 自动引用计数:是的

如果我取消注释这一行:

return (const char*)[fdsa UTF8String];

然后我收到以下错误:

(531,0x19e9ef000) malloc: *** error for object 0x1357d44e1: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

有一些对名为 cocoaToMonoString 的函数的引用,它应该可以解决这个问题,但我找不到任何关于它的示例或文档。

如何将 Xcode 中的字符串返回到 Unity?



Best Answer-推荐答案


只需两美分的贡献。

现在您可以使用 Application.RequestAdvertisingIdentifierAsync 获得 IDFA(或 android 的 GAID)。 :

Application.RequestAdvertisingIdentifierAsync(
        (string advertisingId, bool trackingEnabled, string error) =>
            Debug.Log("advertisingId " + advertisingId + " " + trackingEnabled + " " + error)
);

此外,如果当前平台不支持广告标识符,则该方法返回一个 bool 值,表示成功时为 true;如果当前平台不支持广告标识符,则返回 false。

关于c# - Unity中的Apple idfa通过插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34193282/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4