gpt4 book ai didi

ios - iOS12 中找不到 ASIdentifierManager

转载 作者:可可西里 更新时间:2023-11-01 04:44:52 28 4
gpt4 key购买 nike

我写在这里是因为我真的被困住了,找不到答案。

我们有一个可以在里面收集 IDFA 的小框架。对于 IDFA 集合,我们首先检查 NSClassFromString(@"ASIdentifierManager")

问题是:

假设我们有一个客户端,这个客户端发布了 iOS10-iOS12 版本。并且此客户端获得了 iOS10 和 iOS11 的 IDFA,但对于所有 iOS12 根本没有 IDFA!检查日志后,我们发现 NSClassFromString(@"ASIdentifierManager") 仅适用于 iOS12..

客户端如何添加适用于 iOS10、11 而不是 iOS12 的框架?

另一方面,另一个客户端在 iOS12 上表现不错。

最佳答案

这可能无法完全回答您的问题,只是将我知道的和我的猜测发短信给您。

首先,动态框架只有在你使用时才会加载到你的app进程中,比如iOS模拟器中可用的目录下的框架设备。

> cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks
> # Now there are plenty of frameworks here.
> file AdSupport.framework/AdSupport
Mach-O 64-bit dynamically linked shared library x86_64

如何使用它? TLDR,用 [ASIdentifierManager sharedManager] 调用它当然,在您的任何应用程序中,首先链接到框架并成功编译它。

其次,使用NSClassFromString()有什么区别?直接调用[ASIdentifierManager sharedManager]任何地方?

对于前一种情况,您的应用程序不会加载 AdSupport框架包,因为没有名为 ASIdentifierManager 的符号当操作系统内核加载你的程序时,在你的可执行程序中,可以通过打印你的应用程序主包路径并找到应用程序可执行文件来证明,尝试nm <path/to/executable_app> | grep "ASIdentifierManager" ,因为您没有使用它,所以不会在结果中找到任何东西。

对于后一种,尝试在可执行程序中grep相同的符号,就在那里。

Note: it's not os kernel loads the frameworks by nm result list but the kernel loads the frameworks containing the symbols, check out more info about the dynamic loader dyld.

第三NSClassFromString只检查加载的类,如果 AdSupport框架没有加载,它返回 nil 而没有尝试加载包含目标类的框架。

第四,除非您粘贴有关 IDFA 和 AdSupport 的更多上下文,否则无法记忆起 iOS 10/11 和 iOS 12 之间的区别。项目中的框架使用。这是我的一个猜测,一些依赖库使用 AdSupport框架在早期版本但 iOS 12,你必须尝试转储 iOS 11 和 iOS 12 之间的符号列表并比较结果。

第五,我不确定你想要什么,也许你想避免导入 AdSupport显式框架,如何初始化一个NSBundle按框架路径并调用 -(BOOL)loadNSBundle类,那么你可以得到 Class对象 NSClassFromString .

更新:

NSString *strFrameworkPath = nil;

#if TARGET_OS_SIMULATOR
strFrameworkPath = [[NSProcessInfo processInfo] environment][@"DYLD_FALLBACK_FRAMEWORK_PATH"];
#else
// Assume that the AdSupport and Foundation framework are in the same directory.
strFrameworkPath = [NSBundle bundleForClass:NSPredicate.class].bundlePath;
strFrameworkPath = [strFrameworkPath stringByDeletingLastPathComponent];
#endif

strFrameworkPath = [strFrameworkPath stringByAppendingPathComponent:@"AdSupport.framework"];
NSAssert([[NSFileManager defaultManager] fileExistsAtPath:strFrameworkPath], @"Invalid framework bundle path!");

NSBundle *bundle = [NSBundle bundleWithPath:strFrameworkPath];

if (!bundle.isLoaded) {
NSError *error = nil;

if (![bundle loadAndReturnError:&error]) {
DDLogError(@"Load framework bundle %@ with error %@", bundle, error);
}
}

DDLogDebug(@"bundle: %@", bundle.bundlePath);
DDLogDebug(@"class: %@", NSClassFromString(@"ASIdentifierManager"));

您可能需要增强产品对各种设备的兼容性,有关NSBundle的更多详细信息用法,查看the official documentation here .

关于ios - iOS12 中找不到 ASIdentifierManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53298053/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com