检查IDFA是否可用的动态方式

时间:2016-08-18 06:33:38

标签: ios idfa

我正在开发其他应用将集成的iOS SDK。如果运行我的代码的应用程序与AdSupport.framework相关联,我想使用IDFA进行安装归因。否则不是。

当我使用以下代码时,Apple会拒绝该应用程序吗?

+ (NSString *)appleIDFA {  
    NSString *idfa = nil;  
    Class ASIdentifierManagerClass = NSClassFromString(@"ASIdentifierManager");  

    if (ASIdentifierManagerClass) { 
        SEL sharedManagerSelector = NSSelectorFromString(@"sharedManager");  
        id sharedManager = ((id (*)(id, SEL))[ASIdentifierManagerClass methodForSelector:sharedManagerSelector])(ASIdentifierManagerClass, sharedManagerSelector);  
        SEL advertisingIdentifierSelector = NSSelectorFromString(@"advertisingIdentifier");  
        NSUUID *advertisingIdentifier = ((NSUUID* (*)(id, SEL))[sharedManager methodForSelector:advertisingIdentifierSelector])(sharedManager, advertisingIdentifierSelector);  
        idfa = [advertisingIdentifier UUIDString];  
    }  
    return idfa;  
}

1 个答案:

答案 0 :(得分:0)

我最终使用了这些解决方案并且没有遇到任何问题。