initSDK method
Future<void>
initSDK(
- String appId,
- String appName,
- String _apiUrl,
- String _xTenantId,
- String _xForwardFor,
- String _readApiUrl,
- String _readXTenantId,
- String _readOrganizationId,
- String _readAccessKey,
- String _readAuthScheme,
)
Implementation
Future<void> initSDK(
String appId,
String appName,
String _apiUrl,
String _xTenantId,
String _xForwardFor,
String _readApiUrl,
String _readXTenantId,
String _readOrganizationId,
String _readAccessKey,
String _readAuthScheme
) async {
this._channel.setMethodCallHandler(_handleMethod);
await _setAppId(appId);
await _setAppName(appName);
await _setPushPopupEnabled(true);
// String configs = await rootBundle.loadString('assets/config/api_config.json');
// NtiuspAPIConfig _config = NtiuspAPIConfig.fromJson(configs);
apiUrl = _apiUrl;
xTenantId = _xTenantId;
xForwardFor = _xForwardFor;
readApiUrl = _readApiUrl;
readXTenantId = _readXTenantId;
organizationId = _readOrganizationId;
accessKey = _readAccessKey;
authScheme = _readAuthScheme;
// String readConfigs = await rootBundle.loadString('assets/config/push_read_config.json');
// NtiuspReadAPIConfig _readConfig = NtiuspReadAPIConfig.fromJson(readConfigs);
//
// if (isStage) {
// readApiUrl = _readConfig.apiStgUrl;
// organizationId = _readConfig.stgOrganizationId;
// accessKey = _readConfig.stgAccessKey;
// } else {
// readApiUrl = _readConfig.apiStgUrl;
// organizationId = _readConfig.stgOrganizationId;
// accessKey = _readConfig.stgAccessKey;
// }
// authScheme = _readConfig.authScheme;
// readXTenantId = _readConfig.xTenantId;
if (Platform.isAndroid) {
await _initializeLocalNotifications();
await _configureAndroidChannel();
await _requestNotificationPermissions();
await _initFirebase();
_firebaseMessaging.getToken().then((token) async {
_sendLog("FCM Token: $token");
//자체관리하므로 _sendDeviceInfo를 호출하지 않도록 _checkDeviceInfoWithToken를 호출하지 않음
// if (token != null) {
// await checkDeviceInfoWithToken(token);
// }
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
bool popupEnabled = await _getPushPopupEnabled();
if (popupEnabled && message.data.isNotEmpty) {
NtiuspPushData pushData = NtiuspPushData.fromJson(message.data);
String notiString = pushData.ntiuspNoti ?? "";
Map<String, dynamic> notiMap = json.decode(notiString);
NtiuspNotiData notiData = NtiuspNotiData.fromJson(notiMap);
String title = notiData.notiMsgTitle ?? "알림";
String body = notiData.notiMsg ?? "새로운 메시지가 있습니다.";
String notiType = notiData.notiType ?? "11";
String notiImgUrl = notiData.notiImgUrl ?? "";
// String notiLnkUrl = notiData.notiLnkUrl ?? "";
if (notiType == "13" || notiType == "14") {
try {
final ntiuspHttp.Response response = await ntiuspHttp.get(Uri.parse(notiImgUrl));
final Uint8List bytes = response.bodyBytes;
AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
channelDescription: 'This channel is used for important notifications.',
importance: Importance.high,
priority: Priority.high,
styleInformation: BigPictureStyleInformation(
ByteArrayAndroidBitmap(bytes),
largeIcon: ByteArrayAndroidBitmap(bytes),
),
);
await _flutterLocalNotificationsPlugin.show(
message.hashCode,
title,
body,
NotificationDetails(android: androidPlatformChannelSpecifics),
payload: json.encode({...notiMap, 'notiType': notiType}),
);
} catch (e) {
AndroidNotificationDetails androidPlatformChannelSpecifics = AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
channelDescription: 'This channel is used for important notifications.',
importance: Importance.high,
priority: Priority.high,
);
await _flutterLocalNotificationsPlugin.show(
message.hashCode,
title,
body,
NotificationDetails(android: androidPlatformChannelSpecifics),
payload: json.encode({...notiMap, 'notiType': notiType}),
);
// _sendLog("Error downloading image: $e");
}
} else {
AndroidNotificationDetails androidPlatformChannelSpecifics = const AndroidNotificationDetails(
'high_importance_channel',
'High Importance Notifications',
channelDescription: 'This channel is used for important notifications.',
importance: Importance.high,
priority: Priority.high,
);
await _flutterLocalNotificationsPlugin.show(
message.hashCode,
title,
body,
NotificationDetails(android: androidPlatformChannelSpecifics),
payload: json.encode({...notiMap, 'notiType': notiType}),
);
}
}
String pushMessage = json.encode(message.toJson());
if (_onWillPresentNotificationHandler != null) {
_onWillPresentNotificationHandler!(pushMessage);
}
});
} else if (Platform.isIOS) {
await _initFirebase();
_firebaseMessaging.requestPermission().then((perm) async {
_sendLog("Request Push Notification Permission");
_firebaseMessaging.getAPNSToken().then((token) async {
final tokenString = token?.toLowerCase();
_sendLog("APNS Token: $tokenString");
//자체관리하므로 _sendDeviceInfo를 호출하지 않도록 _checkDeviceInfoWithToken를 호출하지 않음
// if (tokenString != null) {
// await _checkDeviceInfoWithToken(tokenString);
// }
});
});
// UNUserNotificationCenter Delegate 설정 용.
await _channel.invokeMethod("NtiuspPush#initSDK");
}
_sendLog("Ntiusp SDK initialized");
}