ios 获取idfa idfv (uni-app)

摘要

uni-app创建ios应用如何获取手机的idfa以及idfv

本片文章介绍使用uni-app创建ios应用如何获取手机的idfa以及idfv

第一步:编写manifest.json配置文件

在 manifest.json 配置文件 "ios" 下加入frameworks,以及idfa设置为真

"ios" : {
	"frameworks" : [ "AdSupport.framework" ],
	"idfa" : "true"
},

第二步:编辑业务代码,以下是获取idfa,idfv的函数,返回数据为json对象

getIdfa_idfv:function(){
	var NSUUID = plus.ios.importClass('NSUUID');
	var UIDevice = plus.ios.importClass("UIDevice");
	var currentDevice = UIDevice.currentDevice()
	var identifierForVendor = currentDevice.identifierForVendor().UUIDString();
	
	var ASIdentifierManager = plus.ios.importClass("ASIdentifierManager");
	var sharedManager = ASIdentifierManager.sharedManager();
	if(sharedManager.isAdvertisingTrackingEnabled()){
		var advertisingIdentifier = sharedManager.advertisingIdentifier();
		var idfa = plus.ios.invoke(advertisingIdentifier,"UUIDString"); 
	}
	 var result = {'idfa':idfa,'idfv':identifierForVendor}
	 return result;
}

第三步:提交打包测试

注意:不能直接使用Hbuilderx的包测试,需要使用自定义基座,或者打包测试

结果:{"idfa":"7DFFEF3C-FB3A-4121-B0D8-08F7BB0718DF","idfv":"C0EDCF46-7B3F-4AB2-BBAD-95A2FE82982E"}

云竹互联
admin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: