Skip to content

Commit 856748e

Browse files
authored
Merge pull request #271 from Iterable/MOB-1247-fix-collision
[MOB-1247] fix ClassExtensions.swift collisions
2 parents 9b99ad4 + 09a5fde commit 856748e

10 files changed

+86
-54
lines changed

swift-sdk/Internal/ClassExtensions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import Foundation
77
import UIKit
88

9-
public extension Array {
9+
extension Array {
1010
func take(_ size: Int) -> [[Element]] {
1111
return stride(from: 0, to: count, by: size).map {
1212
Array(self[$0 ..< Swift.min($0 + size, count)])
1313
}
1414
}
1515
}
1616

17-
public extension Dictionary where Key == AnyHashable, Value == Any {
17+
extension Dictionary where Key == AnyHashable, Value == Any {
1818
func getValue(for key: JsonKey) -> Any? {
1919
return self[key.jsonKey]
2020
}
@@ -40,7 +40,7 @@ public extension Dictionary where Key == AnyHashable, Value == Any {
4040
}
4141
}
4242

43-
public extension Bundle {
43+
extension Bundle {
4444
var appPackageName: String? {
4545
return bundleIdentifier
4646
}
@@ -72,7 +72,7 @@ extension Encodable {
7272
}
7373
}
7474

75-
public extension UIColor {
75+
extension UIColor {
7676
convenience init?(hex: String) {
7777
guard let int = Int(hex, radix: 16) else {
7878
return nil
@@ -86,13 +86,13 @@ public extension UIColor {
8686
}
8787
}
8888

89-
public extension Data {
89+
extension Data {
9090
func hexString() -> String {
9191
return map { String(format: "%02.2hhx", $0) }.joined()
9292
}
9393
}
9494

95-
public extension Int {
95+
extension Int {
9696
func times(_ f: () -> Void) {
9797
if self > 0 {
9898
for _ in 0 ..< self {

swift-sdk/Internal/InAppDisplayer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ class InAppDisplayer: InAppDisplayerProtocol {
3030
}
3131

3232
/**
33-
Creates and shows a HTML InApp Notification with trackParameters, backgroundColor with callback handler
33+
Creates and shows a HTML In-app Notification with trackParameters, backgroundColor with callback handler
3434

3535
- parameters:
36-
- htmlString: The NSString containing the dialog HTML
36+
- htmlString: The string containing the dialog HTML
3737
- messageMetadata: Message metadata object.
3838
- backgroundAlpha: The background alpha behind the notification
3939
- padding: The padding around the notification

swift-sdk/Internal/InAppHelper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Ported to Swift by Tapash Majumder on 6/7/18.
44
// Copyright © 2018 Iterable. All rights reserved.
55
//
6-
// Utility Methods for inApp
6+
// Utility Methods for in-app
77
// All classes/structs are internal.
88

99
import UIKit

swift-sdk/Internal/InAppManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
277277
showMessage(fromMessagesProcessorResult: messagesProcessorResult)
278278
}
279279

280-
// This must be called from MainThread
280+
// This must be called from Main Thread
281281
private func showInternal(message: IterableInAppMessage,
282282
consume: Bool,
283283
callback: ITBURLCallback? = nil) {
@@ -307,7 +307,7 @@ class InAppManager: NSObject, IterableInternalInAppManagerProtocol {
307307
// set the dismiss time
308308
self.lastDismissedTime = self.dateProvider.currentDate
309309

310-
// check if we need to process more inApps
310+
// check if we need to process more in-apps
311311
self.scheduleNextInAppMessage()
312312

313313
if consume {

swift-sdk/Internal/InAppMessageParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct InAppMessageParser {
2020
}
2121
}
2222

23-
/// Returns an array of Dictionaries holding inApp messages.
23+
/// Returns an array of Dictionaries holding in-app messages.
2424
private static func getInAppDicts(fromPayload payload: [AnyHashable: Any]) -> [[AnyHashable: Any]] {
2525
return payload[JsonKey.InApp.inAppMessages] as? [[AnyHashable: Any]] ?? []
2626
}
@@ -100,7 +100,7 @@ struct InAppMessageParser {
100100
if let theCampaignId = json[JsonKey.campaignId.jsonKey] as? String {
101101
campaignId = theCampaignId
102102
} else {
103-
ITBDebug("Could not find campaignId") // This is debug level because this happens a lot with proof inApps
103+
ITBDebug("Could not find campaignId") // This is debug level because this happens a lot with proof in-apps
104104
campaignId = ""
105105
}
106106

swift-sdk/Internal/IterableAppIntegrationInternal.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import UserNotifications
1010
// Returns whether notifications are enabled
1111
protocol NotificationStateProviderProtocol {
1212
var notificationsEnabled: Promise<Bool, Error> { get }
13+
1314
func registerForRemoteNotifications()
1415
}
1516

@@ -47,7 +48,9 @@ struct SystemNotificationStateProvider: NotificationStateProviderProtocol {
4748
@available(iOS 10.0, *)
4849
public protocol NotificationResponseProtocol {
4950
var userInfo: [AnyHashable: Any] { get }
51+
5052
var actionIdentifier: String { get }
53+
5154
var textInputResponse: UNTextInputNotificationResponse? { get }
5255
}
5356

@@ -72,11 +75,22 @@ struct UserNotificationResponse: NotificationResponseProtocol {
7275
}
7376
}
7477

75-
/// Abstraction of PushTacking
78+
/// Abstraction of push tracking
7679
public protocol PushTrackerProtocol: AnyObject {
7780
var lastPushPayload: [AnyHashable: Any]? { get }
78-
func trackPushOpen(_ userInfo: [AnyHashable: Any], dataFields: [AnyHashable: Any]?, onSuccess: OnSuccessHandler?, onFailure: OnFailureHandler?)
79-
func trackPushOpen(_ campaignId: NSNumber, templateId: NSNumber?, messageId: String?, appAlreadyRunning: Bool, dataFields: [AnyHashable: Any]?, onSuccess: OnSuccessHandler?, onFailure: OnFailureHandler?)
81+
82+
func trackPushOpen(_ userInfo: [AnyHashable: Any],
83+
dataFields: [AnyHashable: Any]?,
84+
onSuccess: OnSuccessHandler?,
85+
onFailure: OnFailureHandler?)
86+
87+
func trackPushOpen(_ campaignId: NSNumber,
88+
templateId: NSNumber?,
89+
messageId: String?,
90+
appAlreadyRunning: Bool,
91+
dataFields: [AnyHashable: Any]?,
92+
onSuccess: OnSuccessHandler?,
93+
onFailure: OnFailureHandler?)
8094
}
8195

8296
extension PushTrackerProtocol {
@@ -140,6 +154,7 @@ struct IterableAppIntegrationInternal {
140154
*/
141155
func application(_ application: ApplicationStateProviderProtocol, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) {
142156
ITBInfo()
157+
143158
if case let NotificationInfo.silentPush(silentPush) = NotificationHelper.inspect(notification: userInfo) {
144159
switch silentPush.notificationType {
145160
case .update:
@@ -184,12 +199,15 @@ struct IterableAppIntegrationInternal {
184199
@available(iOS 10.0, *)
185200
func userNotificationCenter(_: UNUserNotificationCenter?, didReceive response: NotificationResponseProtocol, withCompletionHandler completionHandler: (() -> Void)?) {
186201
ITBInfo()
202+
187203
let userInfo = response.userInfo
204+
188205
// Ignore the notification if we've already processed it from launchOptions while initializing SDK
189206
guard !alreadyTracked(userInfo: userInfo) else {
190207
completionHandler?()
191208
return
192209
}
210+
193211
guard let itbl = IterableAppIntegrationInternal.itblValue(fromUserInfo: userInfo) else {
194212
completionHandler?()
195213
return
@@ -217,7 +235,10 @@ struct IterableAppIntegrationInternal {
217235
}
218236

219237
@available(iOS 10.0, *)
220-
private static func createIterableAction(actionIdentifier: String, userText: String?, userInfo: [AnyHashable: Any], iterableElement itbl: [AnyHashable: Any]) -> IterableAction? {
238+
private static func createIterableAction(actionIdentifier: String,
239+
userText: String?,
240+
userInfo: [AnyHashable: Any],
241+
iterableElement itbl: [AnyHashable: Any]) -> IterableAction? {
221242
var action: IterableAction?
222243

223244
if actionIdentifier == UNNotificationDefaultActionIdentifier {

swift-sdk/IterableAPI.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ import UIKit
360360
/**
361361
Tracks a custom event.
362362

363-
- remark: Pass in the the custom event data.
363+
- remark: Pass in the custom event data.
364364

365365
- parameter eventName: Name of the event
366366
*/
@@ -372,7 +372,7 @@ import UIKit
372372
/**
373373
Tracks a custom event.
374374

375-
- remark: Pass in the the custom event data.
375+
- remark: Pass in the custom event data.
376376

377377
- parameter eventName: Name of the event
378378
- parameter dataFields: A `Dictionary` containing any additional information to save along with the event
@@ -385,7 +385,7 @@ import UIKit
385385
/**
386386
Tracks a custom event.
387387

388-
- remark: Pass in the the custom event data.
388+
- remark: Pass in the custom event data.
389389
- parameters:
390390
- eventName: Name of the event
391391
- dataFields: A `Dictionary` containing any additional information to save along with the event
@@ -431,7 +431,7 @@ import UIKit
431431
// MARK: In-App Notifications
432432

433433
/**
434-
Tracks an InAppOpen event.
434+
Tracks an `InAppOpen` event.
435435
- parameter messageId: The messageId of the notification
436436
*/
437437

@@ -443,7 +443,7 @@ import UIKit
443443
}
444444

445445
/**
446-
Tracks an InAppOpen event.
446+
Tracks an `InAppOpen` event.
447447
Usually you don't need to call this method explicitly. IterableSDK will call this automatically.
448448
Call this method only if you are using a custom view controller to render IterableInAppMessages.
449449

@@ -456,7 +456,7 @@ import UIKit
456456
}
457457

458458
/**
459-
Tracks an InAppClick event
459+
Tracks an `InAppClick` event
460460

461461
- parameter messageId: The messageId of the notification
462462
- parameter buttonURL: The url of the button that was clicked
@@ -470,7 +470,7 @@ import UIKit
470470
}
471471

472472
/**
473-
Tracks an InAppClick event.
473+
Tracks an `InAppClick` event.
474474
Usually you don't need to call this method explicitly. IterableSDK will call this automatically.
475475
Call this method only if you are using a custom view controller to render IterableInAppMessages.
476476

@@ -484,7 +484,7 @@ import UIKit
484484
}
485485

486486
/**
487-
Tracks an InAppClose event
487+
Tracks an `InAppClose` event
488488
- parameter message: The in-app message
489489
- parameter clickedUrl: The url that was clicked to close the in-app. It will be `nil` when message is closed on clicking `back`.
490490
*/
@@ -494,7 +494,7 @@ import UIKit
494494
}
495495

496496
/**
497-
Tracks an InAppClose event
497+
Tracks an `InAppClose` event
498498
- parameter message: The in-app message
499499
- parameter location: The location from where this message was shown. `inbox` or `inApp`.
500500
- parameter clickedUrl: The url that was clicked to close the in-app. It will be `nil` when message is closed on clicking `back`.
@@ -505,7 +505,7 @@ import UIKit
505505
}
506506

507507
/**
508-
Tracks an InAppClose event
508+
Tracks an `InAppClose` event
509509
- parameter message: The in-app message
510510
- parameter location: The location from where this message was shown. `inbox` or `inApp`.
511511
- parameter source: Source is `back` if back button was clicked to dismiss in-app message. Otherwise source is `link`.
@@ -517,7 +517,7 @@ import UIKit
517517
}
518518

519519
/**
520-
Consumes the notification and removes it from the list of inAppMessages
520+
Consumes the notification and removes it from the list of in-app messages
521521

522522
- parameter messageId: The messageId of the notification
523523
*/
@@ -530,7 +530,7 @@ import UIKit
530530
}
531531

532532
/**
533-
Consumes the notification and removes it from the list of inAppMessages
533+
Consumes the notification and removes it from the list of in-app messages
534534

535535
- parameter message: The Iterable message that is being consumed
536536
- parameter location: The location from where this message was shown. `inbox` or `inApp`.
@@ -541,7 +541,7 @@ import UIKit
541541
}
542542

543543
/**
544-
Consumes the notification and removes it from the list of inAppMessages
544+
Consumes the notification and removes it from the list of in-app messages
545545

546546
- parameter message: The Iterable message that is being consumed
547547
- parameter location: The location from where this message was shown. `inbox` or `inApp`.
@@ -618,17 +618,17 @@ import UIKit
618618
return internalImplementation?.handleUniversalLink(url) ?? false
619619
}
620620

621-
/// Use this property for getting and showing inApp Messages.
621+
/// Use this property for getting and showing in-app messages.
622622
/// This property has no meaning if IterableAPI has not been initialized using
623623
/// IterableAPI.initialize
624624
/// ```
625625
/// - IterableAPI.inAppManager.getMessages()
626-
/// - IterableAPI.inappManager.show(message: message, consume: true)
626+
/// - IterableAPI.inAppManager.show(message: message, consume: true)
627627
/// ```
628628
public static var inAppManager: IterableInAppManagerProtocol {
629629
guard let internalImplementation = internalImplementation else {
630-
ITBError("IterableAPI is not initialized yet. InApp will not work now.")
631-
assertionFailure("IterableAPI is not initialized yet. In-app will not work now.")
630+
ITBError("IterableAPI is not initialized yet. In-apps will not work now.")
631+
assertionFailure("IterableAPI is not initialized yet. In-apps will not work now.")
632632
return EmptyInAppManager()
633633
}
634634

swift-sdk/IterableAppIntegration.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ import UserNotifications
1818
* - parameter completionHandler: Completion handler passed from the original call. Iterable will call the completion handler
1919
* automatically if you pass one. If you handle completionHandler in the app code, pass a nil value to this argument.
2020
*/
21-
@objc public static func application(_ application: UIApplication,
22-
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
23-
fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) {
21+
@objc
22+
public static func application(_ application: UIApplication,
23+
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
24+
fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)?) {
2425
ITBInfo()
25-
implementation?.application(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
26+
27+
implementation?.application(application,
28+
didReceiveRemoteNotification: userInfo,
29+
fetchCompletionHandler: completionHandler)
2630
}
2731

2832
/**
@@ -35,9 +39,15 @@ import UserNotifications
3539
* automatically if you pass one. If you handle completionHandler in the app code, pass a nil value to this argument.
3640
*/
3741
@available(iOS 10.0, *)
38-
@objc(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:) public static func userNotificationCenter(_ center: UNUserNotificationCenter?, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: (() -> Void)?) {
42+
@objc(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)
43+
public static func userNotificationCenter(_ center: UNUserNotificationCenter?,
44+
didReceive response: UNNotificationResponse,
45+
withCompletionHandler completionHandler: (() -> Void)?) {
3946
ITBInfo()
40-
implementation?.userNotificationCenter(center, didReceive: UserNotificationResponse(response: response), withCompletionHandler: completionHandler)
47+
48+
implementation?.userNotificationCenter(center,
49+
didReceive: UserNotificationResponse(response: response),
50+
withCompletionHandler: completionHandler)
4151
}
4252

4353
// MARK: Private

swift-sdk/IterableConfig.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import Foundation
3838
/**
3939
* This method is called when new in-app message is available.
4040
* The default behavior is to `show` if you don't override this method.
41-
* - parameter message: `IterableInAppMessage` object containing information regarding inApp to display
42-
* - returns: Return `show` to show the inApp or `skip` to skip this.
41+
* - parameter message: `IterableInAppMessage` object containing information regarding in-app to display
42+
* - returns: Return `show` to show the in-app or `skip` to skip this.
4343
*/
4444
@objc(onNewMessage:) func onNew(message: IterableInAppMessage) -> InAppShowResponse
4545
}
@@ -125,12 +125,12 @@ import Foundation
125125
/// It will log everything >= minLogLevel
126126
public var logDelegate: IterableLogDelegate = DefaultLogDelegate()
127127

128-
/// Implement this protocol to override default inApp behavior.
129-
/// By default, every single inApp will be shown as soon as it is available.
130-
/// If more than 1 inApp is available, we show the first.
128+
/// Implement this protocol to override default in-app behavior.
129+
/// By default, every single in-app will be shown as soon as it is available.
130+
/// If more than 1 in-app is available, we show the first.
131131
public var inAppDelegate: IterableInAppDelegate = DefaultInAppDelegate()
132132

133-
/// How many seconds to wait before showing the next inApp, if there are more than one present
133+
/// How many seconds to wait before showing the next in-app, if there are more than one present
134134
public var inAppDisplayInterval: Double = 30.0
135135

136136
/// These are internal. Do not change

0 commit comments

Comments
 (0)