直接上代碼员咽!
1.控制臺打印
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
NSLog(@"本機idfa=%@",idfa);//控制臺查看
2.使用彈窗顯示并復(fù)制
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"本機IDFA" message:idfa preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"復(fù)制" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
UIPasteboard *pab = [UIPasteboard generalPasteboard];
pab.string = idfa;
}]];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];