Skip to content

Commit bd83ef6

Browse files
Incorporate misc code review changes, typos, error messages etc.
1 parent f2927e5 commit bd83ef6

File tree

10 files changed

+49
-36
lines changed

10 files changed

+49
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Pods/
1010

1111
scripts/
1212

13+
dev.config

Tests/swift-sdk-objc-tests/IterableAPITests.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ - (void)testUniversalDeeplinkNoRewrite {
123123
}
124124

125125
- (void)testHandleUniversalLinkRewrite {
126-
XCTestExpectation *expectation = [self expectationWithDescription:@"High Expectations"];
126+
XCTestExpectation *expectation = [self expectationWithDescription:@"urlDelegate is called"];
127127

128128
MockUrlDelegate *urlDelegateMock = [[MockUrlDelegate alloc] initWithReturnValue:NO];
129129
urlDelegateMock.callback = ^(NSURL *url, IterableActionContext *context) {
@@ -140,9 +140,6 @@ - (void)testHandleUniversalLinkRewrite {
140140
[IterableAPI handleUniversalLink:iterableLink];
141141

142142
[self waitForExpectationsWithTimeout:IterableNetworkResponseExpectationTimeout handler:^(NSError *error) {
143-
if (error) {
144-
NSLog(@"Timeout Error: %@", error);
145-
}
146143
}];
147144
}
148145

Tests/swift-sdk-swift-tests/IterableActionRunnerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class IterableActionRunnerTests: XCTestCase {
6565
let customActionDelegate = MockCustomActionDelegate(returnValue: false)
6666
let action = IterableAction.action(fromDictionary: ["type" : "customActionName"])!
6767
let actionRunner = IterableActionRunner(urlDelegate: nil, customActionDelegate: customActionDelegate, urlOpener: MockUrlOpener())
68-
_ = actionRunner.execute(action: action, from:.push)
68+
_ = actionRunner.execute(action: action, from: .push)
6969

7070
XCTAssertEqual(customActionDelegate.action, action)
7171
}

Tests/swift-sdk-swift-tests/IterableNotificationResponseTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ class IterableNotificationResponseTests: XCTestCase {
200200
}
201201

202202
func testLegacyDeeplinkPayload() {
203+
guard @available(iOS 10, *) else {
204+
return
205+
}
206+
203207
let messageId = UUID().uuidString
204208
let userInfo: [AnyHashable : Any] = [
205209
"itbl" : [

sample-apps/objc-sample-app/objc-sample-app/AppDelegate.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@
1313
@import IterableSDK;
1414

1515
@interface AppDelegate ()
16-
1716
@end
1817

1918
@implementation AppDelegate
19+
NSString *apiKey = @""; // set iterable api key here
20+
NSString *email = @""; // set iterable email here
2021

2122

2223
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
24+
// initial check
25+
if (apiKey.length == 0 || email.length == 0) {
26+
[NSException raise:@"Not Initialized" format:@"Iterable API key and email must be set."];
27+
}
28+
2329
//ITBL: Setup Notifications
2430
[self setupNotifications];
2531

@@ -30,10 +36,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3036
config.pushIntegrationName = @"objc-sample-app";
3137
config.sandboxPushIntegrationName = @"objc-sample-app";
3238

33-
[IterableAPI initializeWithApiKey:@"a415841b631a4c97924bc09660c658fc"
39+
[IterableAPI initializeWithApiKey: apiKey
3440
launchOptions:launchOptions
3541
config:config];
36-
IterableAPI.sharedInstance.email = @"[email protected]";
42+
IterableAPI.sharedInstance.email = email;
3743

3844
return YES;
3945
}
@@ -107,7 +113,7 @@ - (BOOL)handleIterableURL:(NSURL *)url context:(IterableActionContext *)context
107113
- (BOOL)handleIterableCustomAction:(IterableAction *)action context:(IterableActionContext *)context {
108114
if ([action.type isEqualToString:@"handleFindCoffee"]) {
109115
if (action.userInput != nil) {
110-
NSString *urlString = [[NSString alloc] initWithFormat:@"https://majumder/me/coffee?q=%@", action.userInput];
116+
NSString *urlString = [[NSString alloc] initWithFormat:@"https://majumder.me/coffee?q=%@", action.userInput];
111117
NSURL *url = [[NSURL alloc] initWithString:urlString];
112118
[DeeplinkHandler handleURL:url];
113119
}

sample-apps/swift-sample-app/swift-sample-app/AppDelegate.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ import IterableSDK
1313

1414
@UIApplicationMain
1515
class AppDelegate: UIResponder, UIApplicationDelegate {
16-
16+
// ITBL: replace with your api key and email.
17+
let apiKey = "" // set Iterable api key here
18+
let email = "" // set Iterable user email here.
19+
1720
var window: UIWindow?
1821

1922
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
23+
// Initial check
24+
if apiKey.isEmpty || email.isEmpty {
25+
fatalError("Iterable API Key and email need to be set.")
26+
}
27+
2028
//ITBL: Setup Notification
2129
setupNotifications()
2230

@@ -26,11 +34,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2634
config.urlDelegate = self
2735
config.pushIntegrationName = "swift-sample-app"
2836
config.sandboxPushIntegrationName = "swift-sample-app"
29-
// !! Replace with your api key and email here.
30-
IterableAPI.initialize(apiKey:"a415841b631a4c97924bc09660c658fc",
37+
// Replace with your api key and email here.
38+
IterableAPI.initialize(apiKey: apiKey,
3139
launchOptions:launchOptions,
3240
config: config)
33-
IterableAPI.sharedInstance?.email = "[email protected]"
41+
IterableAPI.sharedInstance?.email = email
3442

3543
return true
3644
}

swift-sdk/IterableAPI+Internal.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ extension IterableAPI {
3838
}
3939
if let remoteNotificationPayload = launchOptions[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable : Any] {
4040
if let _ = IterableUtil.rootViewController {
41+
// we are ready
42+
IterableAppIntegration.minion?.performDefaultNotificationAction(remoteNotificationPayload)
43+
} else {
4144
// keywindow not set yet
4245
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
4346
IterableAppIntegration.minion?.performDefaultNotificationAction(remoteNotificationPayload)
4447
}
45-
46-
} else {
47-
// we are ready
48-
IterableAppIntegration.minion?.performDefaultNotificationAction(remoteNotificationPayload)
4948
}
5049
}
5150
}
@@ -94,18 +93,16 @@ extension IterableAPI {
9493
ITBL_KEY_EMAIL: email,
9594
ITBL_KEY_DEVICE: deviceDictionary
9695
]
96+
} else if let userId = userId {
97+
args = [
98+
ITBL_KEY_USER_ID: userId,
99+
ITBL_KEY_DEVICE: deviceDictionary
100+
]
97101
} else {
98-
if let userId = userId {
99-
args = [
100-
ITBL_KEY_USER_ID: userId,
101-
ITBL_KEY_DEVICE: deviceDictionary
102-
]
103-
} else {
104-
ITBError("Either email or userId is required.")
105-
args = [
106-
ITBL_KEY_DEVICE: deviceDictionary
107-
]
108-
}
102+
ITBError("Either email or userId is required.")
103+
args = [
104+
ITBL_KEY_DEVICE: deviceDictionary
105+
]
109106
}
110107

111108
ITBInfo("sending registerToken request with args \(args)")

swift-sdk/IterableAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,8 @@ import Foundation
810810
- returns: true if it is an Iterable link, or the value returned from `IterableURLDelegate` otherwise
811811
*/
812812
@objc @discardableResult public static func handleUniversalLink(_ url: URL) -> Bool {
813-
if let zeeInstance = _sharedInstance {
814-
return zeeInstance.deeplinkManager.handleUniversalLink(url)
813+
if let instance = _sharedInstance {
814+
return instance.deeplinkManager.handleUniversalLink(url)
815815
} else {
816816
return false
817817
}

swift-sdk/IterableAPNSUtil.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ struct IterableAPNSUtil {
6666
let scanner = Scanner(string: string)
6767
var buffer: NSString?
6868
guard
69-
scanner.scanUpTo(begin, into: nil)
70-
,scanner.scanUpTo(end, into: &buffer)
71-
,let plistString = buffer
69+
scanner.scanUpTo(begin, into: nil),
70+
scanner.scanUpTo(end, into: &buffer),
71+
let plistString = buffer
7272

7373
else {
7474
return nil

swift-sdk/IterableDeeplinkManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class IterableDeeplinkManager : NSObject {
4040
- returns: true if it is an Iterable link, or the value returned from `IterableURLDelegate` otherwise
4141
*/
4242
func handleUniversalLink(_ url: URL) -> Bool {
43-
if isDeeplink(url.absoluteString) {
43+
if isIterableDeeplink(url.absoluteString) {
4444
resolve(applinkURL: url) {[actionRunner] (resolvedUrl) in
4545
var resolvedUrlString: String
4646
if let resolvedUrl = resolvedUrl {
@@ -76,7 +76,7 @@ class IterableDeeplinkManager : NSObject {
7676
deeplinkTemplateId = nil
7777
deeplinkMessageId = nil
7878

79-
if isDeeplink(applinkURL.absoluteString) {
79+
if isIterableDeeplink(applinkURL.absoluteString) {
8080
let trackAndRedirectTask = redirectUrlSession.dataTask(with: applinkURL) {[unowned self] (data, response, error) in
8181
if let error = error {
8282
ITBError("error: \(error.localizedDescription)")
@@ -98,7 +98,7 @@ class IterableDeeplinkManager : NSObject {
9898
}
9999
}
100100

101-
private func isDeeplink(_ urlString: String) -> Bool {
101+
private func isIterableDeeplink(_ urlString: String) -> Bool {
102102
guard let regex = try? NSRegularExpression(pattern: ITBL_DEEPLINK_IDENTIFIER, options: []) else {
103103
return false
104104
}

0 commit comments

Comments
 (0)