Skip to content

Commit 2bcea05

Browse files
committed
docs(includes):notification service description, init params fo iOS
Signed-off-by: Aleksandr_Zavadkin <az@rees46.ru>
1 parent ca3ad80 commit 2bcea05

File tree

2 files changed

+47
-31
lines changed

2 files changed

+47
-31
lines changed

source/includes/_init.md.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ curl https://<%= config[:api_endpoint] %>/init?did=DEVICE_ID&shop_id=SHOP_ID&v=3
127127

128128
```swift
129129
import <%= config[:ios_sdk_package_name] %>
130-
var sdk = createPersonalizationSDK(shopId: "SHOP_ID", stream: "ios")
130+
var sdk = createPersonalizationSDK(shopId: "SHOP_ID", stream: "ios", userEmail: "exmample@mail.ru", userPhone: "String", userLoyaltyId: "String", apiDomain: "String", enableLogs: Bool, autoSendPushToken: Bool)
131131
```
132132

133133
```java

source/includes/_notification_service.md.erb

+46-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
1-
// Example of SimplePersonalizationSDK initialization with autoSendPushToken flag set to true
2-
3-
let personalizationSDK = SimplePersonalizationSDK(autoSendPushToken: true)
4-
5-
// Example of initializing NotificationService
6-
let notificationService = NotificationService(sdkInstance: personalizationSDK)
7-
8-
// Example of integrating NotificationService in AppDelegate
9-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
10-
// Initialize NotificationService
11-
let notificationService = NotificationService(sdkInstance: personalizationSDK)
12-
13-
// Request permission for remote notifications
14-
UIApplication.shared.registerForRemoteNotifications()
15-
16-
return true
1+
# The first step is setting `autoSendPushToken = true` during SDK initialization
2+
# `NotificationService` object is initializing in `SimplePersonalizationSDK`
3+
# `NotificationService` will check `autoSendPushToken ` value. If true - the last sending date check.
4+
# Check results: nil - token will be sent to the server and the date will be saved. More than a week - the token will be sent and the token sending date will be renewed.
5+
# Less than a week - token won`t be sent.
6+
# If `autoSendPushToken` value is false NotificationService won`t send the token to the server
7+
8+
@UIApplicationMain
9+
10+
class AppDelegate:UIResponder,UIApplicationDelegate {
11+
var window:UIWindow?
12+
13+
let gcmMessageIDKey = "gcm.message_id"
14+
var sdk:PersonalizationSDK!
15+
var sdkAdditionalInit:PersonalizationSDK!
16+
var NotificationService:NotificationServiceProtocol?
17+
18+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
19+
20+
print("A. init firebase SDK")
21+
FirebaseApp.configure()
22+
Messaging.messaging().delegate = self
23+
print("======")
24+
25+
print("0 init SDK")
26+
sdk = createPersonalizationSDK(shopId:String, enableLogs: Boolean, { error in
27+
didToken = self.sdk.getDeviceId()
28+
globalSDK = self.sdk
29+
NotificationCenter.default.post(name: globalSDKNotificationNameMainInit, object: nil)
30+
})
31+
notificationService = NotificationService(sdk: sdk)
32+
notificationService?.pushActionDelegate = self
33+
34+
}
1735
}
1836

19-
// Example of implementing UNUserNotificationCenterDelegate
20-
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
37+
# During initialization `NotificationService ` will ask permission from the user to send notifications - UIApplication.shared.registerForRemoteNotifications()
38+
# The client will have to sign protocols - UNUserNotificationCenterDelegate and implement the `application` method and call the `application` method inside of the NotificationService object application
2139

22-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
23-
// Initialize NotificationService
24-
let notificationService = NotificationService(sdkInstance: personalizationSDK)
40+
extension AppDelegate: UNUserNotificationCenterDelegate {
41+
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){
42+
let tokenParts = deviceToken.map { data -> String in String(format: "%02.2hhx",data) }
2543

26-
// Request permission for remote notifications
27-
UIApplication.shared.registerForRemoteNotifications()
44+
let token = tokenParts.joined()
45+
pushGlobalToken = token
46+
print("Push Token", pushGlobalToken)
47+
userDefaults.standard.set(token,forkey: "pushGlobalToken")
2848

29-
return true
30-
}
49+
Messaging.messaging().apnsToken = deviceToken
50+
51+
notificationService?didRegisterForRemoteNotificationsWithDeviceToken(deviceToken: deviceToken)
3152

32-
// Implement method for receiving device token
33-
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
34-
// Pass device token to NotificationService
35-
notificationService.didRegisterForRemoteNotifications(with: deviceToken)
3653
}
3754
}
38-
//TODO change examples so they would look like code on screenshot attached to the task

0 commit comments

Comments
 (0)