setIdfaString method
dynamic
setIdfaString(
- String value,
- bool isAuthorized
)
Implementation
setIdfaString(String value, bool isAuthorized) async {
if (value == "") {
await FlutterKeychain.remove(key: "idfa");
checkNotification.value = "";
update();
return;
}
if (isAuthorized) {
var idfa = await FlutterKeychain.get(key: "idfa");
print('idfa: $value');
if (idfa == null || idfa == "") {
await FlutterKeychain.put(key: "idfa", value: value);
checkNotification.value = value;
} else {
checkNotification.value = idfa;
}
} else {
var idfa = await FlutterKeychain.get(key: "idfa");
if (idfa == null || idfa == "" || idfa.startsWith('000000')) {
String appName = BZMCenter.to.appName;
const chars =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
final random = Random();
int remainingLength = 32 - appName.length;
if (remainingLength <= 0) {
value = appName.substring(0, 32);
} else {
String randomPart = List.generate(
remainingLength,
(index) => chars[random.nextInt(chars.length)],
).join();
value = appName + randomPart;
}
value = md5.convert(utf8.encode(value)).toString();
await FlutterKeychain.put(key: "idfa", value: value);
checkNotification.value = value;
} else {
checkNotification.value = idfa;
}
}
update();
}