forked from SelligentMarketingCloud/MobileSDK-ReactNative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
145 lines (126 loc) · 5.17 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// iOS specific methods
import { NativeEventEmitter, NativeModules } from 'react-native'
import SelligentConstants from './constants'
import SelligentHelpers from './helpers'
const { RNSelligent } = NativeModules
const RNSEventEmitter = new NativeEventEmitter(RNSelligent)
export default {
// Basic SMManager
// InAppMessage
/**
* Enable/disable in-app messages on iOS.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {boolean} enabled Boolean to enable/disable in-app messages.
*/
enableInAppMessages: function (successCallback, errorCallback, enabled) {
if (!SelligentHelpers.typeMatches(enabled, 'boolean')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a boolean.'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.enableInAppMessages(enabled)
return
},
// Log
/**
* Enable logging messages on iOS.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {array} logLevels Array of logging levels that should be enabled.
*/
enableiOSLogging: function (successCallback, errorCallback, logLevels) {
if (!SelligentHelpers.typeMatches(logLevels, 'array')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected an array of numbers.'))
return
}
// check if values are all numbers and iOS Loglevels
var arrayLength = logLevels.length
for (var i = 0; i < arrayLength; i++) {
if (!SelligentHelpers.typeMatches(logLevels[i], 'number')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a number.'))
return
}
if (!SelligentHelpers.constantIsValid(SelligentConstants.iOSLogLevel, logLevels[i])) {
errorCallback(SelligentHelpers.createTypeErrorMessage('iOSloglevel', logLevels[i], 'number'))
return
}
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.applyLogLevel(logLevels)
return
},
// Remote Notification
/**
* Display notification by id on iOS.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} notificationId Id of the notification.
*/
displayNotification: function (successCallback, errorCallback, notificationId) {
if (!SelligentHelpers.typeMatches(notificationId, 'string') || notificationId.length === 0) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string (not empty).'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.displayNotification(notificationId)
return
},
/**
* Register a completion handler for successfully fetching remote notifications.
*
* @param {function} successCallback Completion handler.
* @param {function} eventCallback Callback function on event.
*/
registerRemoteNotificationFetchCompletionHandler: function (successCallback, eventCallback) {
RNSEventEmitter.addListener(SelligentConstants.RemoteNotification.FETCHED_REMOTE_NOTIFICATION, eventCallback);
successCallback(SelligentHelpers.SUCCESS)
return
},
/**
* Force the result of a remote notification fetch to be a specific value.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {iOSBackgroundFetchResult} iOSBackgroundFetchResult Type of result to force, when fetching remote notifications.
*/
forceRemoteNotificationBackgroundFetchResult: function (successCallback, errorCallback, iOSBackgroundFetchResult) {
if (!SelligentHelpers.typeMatches(iOSBackgroundFetchResult, 'number') || !SelligentHelpers.constantIsValid(SelligentConstants.iOSBackgroundFetchResult, iOSBackgroundFetchResult)) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a value of Selligent constant enum "iOSBackgroundFetchResult".'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.forceRemoteNotificationBackgroundFetchResult(iOSBackgroundFetchResult)
return
},
/**
* Register for Provisional Push Notifications.
*
* @param {function} successCallback Callback function on success.
*/
registerForProvisionalRemoteNotification: function (successCallback) {
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.registerForProvisionalRemoteNotification()
return
},
// Broadcasts Events
/**
* Subscribe to events.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {function} eventCallback Callback function on event.
*/
subscribeToEvents: function (successCallback, errorCallback, eventCallback) {
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.RECEIVED_IN_APP_MESSAGE, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.WILL_DISPLAY_NOTIFICATION, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.WILL_DISMISS_NOTIFICATION, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.RECEIVED_REMOTE_NOTIFICATION, eventCallback);
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.subscribeToEvents()
return
}
}