Skip to content

Commit 12aa02d

Browse files
Merge pull request #423 from Iterable/bug/mob-2343-rn-initialization
[MOB-2343] - RN initialization
2 parents dd27e72 + 0ce9e8f commit 12aa02d

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

swift-sdk/Internal/IterableAPIInternal.swift

+25
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ final class IterableAPIInternal: NSObject, PushTrackerProtocol, AuthProvider {
357357

358358
private var config: IterableConfig
359359

360+
// Following are needed for handling pending notification and deep link.
361+
static var pendingNotificationResponse: NotificationResponseProtocol?
362+
static var pendingUniversalLink: URL?
363+
360364
private let dateProvider: DateProviderProtocol
361365
private let inAppDisplayer: InAppDisplayerProtocol
362366
private var notificationStateProvider: NotificationStateProviderProtocol
@@ -514,6 +518,11 @@ final class IterableAPIInternal: NSObject, PushTrackerProtocol, AuthProvider {
514518

515519
handle(launchOptions: launchOptions)
516520

521+
522+
handlePendingNotification()
523+
524+
handlePendingUniversalLink()
525+
517526
requestProcessor.start()
518527

519528
return inAppManager.start()
@@ -536,6 +545,22 @@ final class IterableAPIInternal: NSObject, PushTrackerProtocol, AuthProvider {
536545
}
537546
}
538547

548+
private func handlePendingNotification() {
549+
if let pendingNotificationResponse = Self.pendingNotificationResponse {
550+
if #available(iOS 10.0, *) {
551+
IterableAppIntegration.implementation?.userNotificationCenter(nil, didReceive: pendingNotificationResponse, withCompletionHandler: nil)
552+
}
553+
Self.pendingNotificationResponse = nil
554+
}
555+
}
556+
557+
private func handlePendingUniversalLink() {
558+
if let pendingUniversalLink = Self.pendingUniversalLink {
559+
handleUniversalLink(pendingUniversalLink)
560+
Self.pendingUniversalLink = nil
561+
}
562+
}
563+
539564
private func checkForDeferredDeepLink() {
540565
guard config.checkForDeferredDeeplink else {
541566
return

swift-sdk/Internal/IterableAppIntegrationInternal.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ struct SystemNotificationStateProvider: NotificationStateProviderProtocol {
4747
}
4848
}
4949

50-
@available(iOS 10.0, *)
5150
public protocol NotificationResponseProtocol {
5251
var userInfo: [AnyHashable: Any] { get }
5352

5453
var actionIdentifier: String { get }
5554

56-
var textInputResponse: UNTextInputNotificationResponse? { get }
55+
var userText: String? { get }
5756
}
5857

5958
@available(iOS 10.0, *)
@@ -66,8 +65,12 @@ struct UserNotificationResponse: NotificationResponseProtocol {
6665
response.actionIdentifier
6766
}
6867

69-
var textInputResponse: UNTextInputNotificationResponse? {
70-
response as? UNTextInputNotificationResponse
68+
var userText: String? {
69+
guard let textInputResponse = response as? UNTextInputNotificationResponse else {
70+
return nil
71+
}
72+
73+
return textInputResponse.userText
7174
}
7275

7376
private let response: UNNotificationResponse
@@ -217,8 +220,8 @@ struct IterableAppIntegrationInternal {
217220
return
218221
}
219222

220-
let dataFields = IterableAppIntegrationInternal.createIterableDataFields(actionIdentifier: response.actionIdentifier, userText: response.textInputResponse?.userText)
221-
let action = IterableAppIntegrationInternal.createIterableAction(actionIdentifier: response.actionIdentifier, userText: response.textInputResponse?.userText, userInfo: userInfo, iterableElement: itbl)
223+
let dataFields = IterableAppIntegrationInternal.createIterableDataFields(actionIdentifier: response.actionIdentifier, userText: response.userText)
224+
let action = IterableAppIntegrationInternal.createIterableAction(actionIdentifier: response.actionIdentifier, userText: response.userText, userInfo: userInfo, iterableElement: itbl)
222225

223226
// Track push open
224227
if let _ = dataFields[JsonKey.actionIdentifier.jsonKey] { // i.e., if action is not dismiss

swift-sdk/IterableAppIntegration.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ import UserNotifications
4545
withCompletionHandler completionHandler: (() -> Void)?) {
4646
ITBInfo()
4747

48-
implementation?.userNotificationCenter(center,
49-
didReceive: UserNotificationResponse(response: response),
50-
withCompletionHandler: completionHandler)
48+
if let implementation = implementation {
49+
implementation.userNotificationCenter(center,
50+
didReceive: UserNotificationResponse(response: response),
51+
withCompletionHandler: completionHandler)
52+
} else {
53+
IterableAPIInternal.pendingNotificationResponse = UserNotificationResponse(response: response)
54+
}
5155
}
5256

5357
// MARK: Private

tests/common/CommonMocks.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct MockNotificationResponse: NotificationResponseProtocol {
2323
self.actionIdentifier = actionIdentifier
2424
}
2525

26-
var textInputResponse: UNTextInputNotificationResponse? {
26+
var userText: String? {
2727
nil
2828
}
2929
}

0 commit comments

Comments
 (0)