checkDeviceInfoWithToken method
Implementation
Future<void> checkDeviceInfoWithToken(String token) async {
//device Info 저장 (푸시토큰 얻은 후 서버 전송)
//FCM 토큰을 얻은 뒤
//localDeviceInfo가 없으면 /v1/devices
//있고 현재 deviceInfo의 appVer, osVer, model, Token 중 하나라도 값이 다르다면
//audienceID가 있으면 사용자프로필 정보를 가져와서 /v1/audiences
//audienceId가 없으면 /v1/devices 호출
NtiuspDeviceInfo? prevDeviceInfo = await _getLocalDeviceInfo();
NtiuspDeviceInfo currentDeviceInfo = await _getDeviceInfo();
currentDeviceInfo.pushToken = token;
if (prevDeviceInfo == null) {
_sendDeviceInfo(currentDeviceInfo);
} else {
if (currentDeviceInfo.app?.appVersion != prevDeviceInfo.app?.appVersion ||
currentDeviceInfo.pushToken != prevDeviceInfo.pushToken ||
currentDeviceInfo.osVersion != prevDeviceInfo.osVersion ||
currentDeviceInfo.modelNo != prevDeviceInfo.modelNo) {
String? audienceId = await _getAudienceId();
if (audienceId != null) {
NtiuspClientInfo? clientInfo = await _getLocalClientInfo();
if (clientInfo == null) {
//audienceId가 있는데 client정보가 없다면 에러
return;
}
clientInfo.devices = [currentDeviceInfo];
await _sendClientInfo(clientInfo);
//기기정보가 바뀌었으면 신규 기기정보도 저장한다.
_setLocalDeviceInfo(currentDeviceInfo);
} else {
await _sendDeviceInfo(currentDeviceInfo);
}
}
}
}