Skip to content

Commit a3488e9

Browse files
cleanUp and additional lifecycle methods available for objc requests
1 parent 0b3074d commit a3488e9

17 files changed

+187
-169
lines changed

BreinifyApi/api/BreinActivity.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ open class BreinActivity: BreinBase, ISecretStrategy {
7474
@discardableResult
7575
@objc
7676
public func setDescription(_ description: String!) -> BreinActivity {
77-
self.desc = description
77+
desc = description
7878
return self
7979
}
8080

@@ -93,14 +93,14 @@ open class BreinActivity: BreinBase, ISecretStrategy {
9393
}
9494

9595
public func getTagsDic() -> [String: Any]? {
96-
self.tagsDic
96+
tagsDic
9797
}
9898

9999
@discardableResult
100100
@objc
101101
public func setTag(_ key: String, _ value: AnyObject) -> BreinActivity {
102-
if self.tagsDic == nil {
103-
self.tagsDic = [String: Any]()
102+
if tagsDic == nil {
103+
tagsDic = [String: Any]()
104104
}
105105

106106
tagsDic?[key] = value
@@ -114,7 +114,7 @@ open class BreinActivity: BreinBase, ISecretStrategy {
114114
}
115115

116116
public func getActivityDic() -> [String: Any]? {
117-
self.activityDic
117+
activityDic
118118
}
119119

120120
/// Sends an activity to the Breinify server.
@@ -211,12 +211,12 @@ open class BreinActivity: BreinBase, ISecretStrategy {
211211

212212
// create a new activity object
213213
let clonedBreinActivity = BreinActivity()
214-
.setActivityType(self.getActivityType())
215-
.setCategory(self.getCategory())
216-
.setDescription(self.getDescription())
214+
.setActivityType(getActivityType())
215+
.setCategory(getCategory())
216+
.setDescription(getDescription())
217217

218218
// clone dictionaries => simple copy is enough
219-
if let clonedActivityDic = self.getActivityDic() {
219+
if let clonedActivityDic = getActivityDic() {
220220
clonedBreinActivity.setActivityDic(clonedActivityDic)
221221
}
222222

@@ -247,8 +247,8 @@ open class BreinActivity: BreinBase, ISecretStrategy {
247247
/// - Throws: BreinRuntimeError
248248
public override func createSignature() throws -> String! {
249249

250-
let breinActivityType = self.getActivityType() ?? ""
251-
let unixTimestamp = self.getUnixTimestamp()
250+
let breinActivityType = getActivityType() ?? ""
251+
let unixTimestamp = getUnixTimestamp()
252252
let message = breinActivityType + String(unixTimestamp) + "1"
253253

254254
return try BreinUtil.generateSignature(message, secret: getConfig()?.getSecret())

BreinifyApi/api/BreinIpInfo.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ open class BreinIpInfo {
6060
/// provides external ipAddress
6161
public func getExternalIp() -> String? {
6262

63-
guard self.readDataMap != nil else {
63+
guard readDataMap != nil else {
6464
return ""
6565
}
6666

67-
if let ip = self.readDataMap?[BreinIpInfo.kIpField] as? String {
67+
if let ip = readDataMap?[BreinIpInfo.kIpField] as? String {
6868
return ip
6969
}
7070

@@ -74,8 +74,8 @@ open class BreinIpInfo {
7474
/// provides timezone
7575
public func getTimezone() -> String? {
7676

77-
if self.readDataMap != nil {
78-
if let timeZone = self.readDataMap?[BreinIpInfo.kTimezoneField] as? String {
77+
if readDataMap != nil {
78+
if let timeZone = readDataMap?[BreinIpInfo.kTimezoneField] as? String {
7979
return timeZone
8080
}
8181
return ""

BreinifyApi/api/BreinLocationManager.swift

+8-10
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ public class BreinLocationManager: NSObject, CLLocationManagerDelegate {
7373
///
7474
public override init() {
7575
super.init()
76-
self.ignoreLocationRequestState = false
76+
ignoreLocationRequestState = false
7777
}
7878

7979
// ctor with option to ignore request
8080
public init(ignoreLocationRequest: Bool) {
8181
super.init()
82-
self.ignoreLocationRequestState = ignoreLocationRequest
82+
ignoreLocationRequestState = ignoreLocationRequest
8383
}
8484

8585
// ignore request
8686
public func ignoreLocationRequest() -> Bool {
87-
self.ignoreLocationRequestState
87+
ignoreLocationRequestState
8888
}
8989

9090
// ignore request
9191
public func setIgnoreLocationRequest(ignoreLocationRequest: Bool) -> BreinLocationManager {
92-
self.ignoreLocationRequestState = ignoreLocationRequest
92+
ignoreLocationRequestState = ignoreLocationRequest
9393
return self
9494
}
9595

@@ -102,28 +102,26 @@ public class BreinLocationManager: NSObject, CLLocationManagerDelegate {
102102
}
103103

104104
/// location authorization status changed
105-
@nonobjc
106105
public func locationManager(_ manager: CLLocationManager,
107-
didChangeAuthorizationStatus status: CLAuthorizationStatus) {
106+
didChangeAuthorization status: CLAuthorizationStatus) {
108107

109108
switch status {
110109
case .authorizedWhenInUse,
111110
.authorizedAlways,
112111
.notDetermined:
113-
self.locationManager.startUpdatingLocation()
112+
locationManager.startUpdatingLocation()
114113

115114
// it's fine to send sendLoc information
116115
BreinifyManager.shared.hasPermissionToSendLocationUpdates = true
117116

118117
default:
119-
completionHandler(location: dummyLocation, error: NSError(domain: self.classForCoder.description(),
118+
completionHandler(location: dummyLocation, error: NSError(domain: classForCoder.description(),
120119
code: BreinLocationManagerErrors.AuthorizationDenied.rawValue,
121120
userInfo: nil))
122121
}
123122
}
124123

125124
// invoked in case of a failure
126-
@nonobjc
127125
public func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
128126
completionHandler(location: dummyLocation, error: error)
129127
}
@@ -151,7 +149,7 @@ public class BreinLocationManager: NSObject, CLLocationManagerDelegate {
151149
didComplete = completion
152150

153151
// check if location request should be ignored
154-
if self.ignoreLocationRequest() == true {
152+
if ignoreLocationRequest() == true {
155153
completionHandler(location: dummyLocation, error: NSError(domain: "BreinLocationManager", code: 103, userInfo: nil))
156154
}
157155

BreinifyApi/api/BreinNotificationServiceExtension.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ open class BreinNotificationServiceExtension: UNNotificationServiceExtension {
1515

1616
open override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
1717
self.contentHandler = contentHandler
18-
self.receivedRequest = request
18+
receivedRequest = request
1919
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
2020

2121
if let bestAttemptContent = bestAttemptContent {
2222
// Modify the notification content here...
23-
Breinify.didReceiveNotificationExtensionRequest(self.receivedRequest as Any, bestAttemptContent: bestAttemptContent)
23+
Breinify.didReceiveNotificationExtensionRequest(receivedRequest as Any, bestAttemptContent: bestAttemptContent)
2424
contentHandler(bestAttemptContent)
2525
}
2626
}

BreinifyApi/api/Breinify.swift

+23-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open class Breinify: NSObject {
1111
typealias apiFailure = (_ error: NSDictionary) -> Void
1212

1313
/// contains the current version of the library
14-
static let version: String! = "2.0.19"
14+
static let version: String! = "2.0.20"
1515

1616
/// contains the configuration
1717
static var config: BreinConfig?
@@ -71,6 +71,19 @@ open class Breinify: NSObject {
7171
BreinifyManager.shared.handleDidReceiveNotification(notification)
7272
}
7373

74+
@available(iOS 10, *)
75+
@objc
76+
public static func didReceiveNotificationResponse(_ response: UNNotificationResponse) {
77+
BreinLogger.shared.log("Breinify didReceiveNNotificationResponse invoked")
78+
BreinifyManager.shared.handleDidReceiveNotificationResponse(response)
79+
}
80+
81+
@objc
82+
public static func didReceive(_ notification: [AnyHashable : Any]) {
83+
BreinLogger.shared.log("Breinify didReceive invoked")
84+
BreinifyManager.shared.handleDidReceiveNotification(notification)
85+
}
86+
7487
@objc
7588
public static func willPresentNotification(_ notification: [AnyHashable : Any]) {
7689
BreinLogger.shared.log("Breinify willPresentNotification invoked")
@@ -79,7 +92,7 @@ open class Breinify: NSObject {
7992

8093
@objc
8194
public static func isBreinifyNotification(_ userInfo: [AnyHashable : Any]) -> Bool {
82-
return userInfo.keys.contains("breinify")
95+
userInfo.keys.contains("breinify")
8396
}
8497

8598
@objc
@@ -626,7 +639,7 @@ open class Breinify: NSObject {
626639
- Parameter activityType: The type of the activity collected, i.e., one of search, login, logout, addToCart,
627640
removeFromCart, checkOut, selectProduct, or other. if not specified, the default other will
628641
be used
629-
- Parameter categoryType: The category of the platform/service/products, i.e., one of apparel, home, education, family,
642+
- Parameter category: The category of the platform/service/products, i.e., one of apparel, home, education, family,
630643
food, health, job, services, or other
631644
- Parameter description: A string with further information about the activity performed
632645
- Parameter success: A callback function that is invoked in case of success.
@@ -789,7 +802,7 @@ open class Breinify: NSObject {
789802

790803
Furthermore it uses the internal instance of BreinTemporalData.
791804

792-
- parameter ipAddress: Contains an ipAddress to resolve.
805+
- Parameter ipAddress: Contains an ipAddress to resolve.
793806
- Parameter success: A callback function that is invoked in case of success.
794807
- Parameter failure: A callback function that is invoked in case of an error.
795808

@@ -828,7 +841,7 @@ open class Breinify: NSObject {
828841

829842
Furthermore it uses the internal instance of BreinTemporalData.
830843

831-
- parameter breinTemporalData: Contains a breinTemporalData object.
844+
- Parameter breinTemporalData: Contains a breinTemporalData object.
832845
- Parameter success: A callback function that is invoked in case of success.
833846
- Parameter failure: A callback function that is invoked in case of an error.
834847

@@ -870,8 +883,8 @@ open class Breinify: NSObject {
870883
Retrieves a lookup result from the engine. The function needs a valid API-key to be configured to succeed.
871884
This request is synchronous.
872885

873-
- parameter user: A plain object specifying information about the user to retrieve data for.
874-
- parameter dimension: An object (with an array) containing the names of the dimensions to lookup.
886+
- Parameter user: A plain object specifying information about the user to retrieve data for.
887+
- Parameter dimension: An object (with an array) containing the names of the dimensions to lookup.
875888
- Parameter success: A callback function that is invoked in case of success.
876889
- Parameter failure: A callback function that is invoked in case of an error.
877890

@@ -899,9 +912,9 @@ open class Breinify: NSObject {
899912
Retrieves a lookup result from the engine. The function needs a valid API-key to be configured to succeed.
900913
This request is synchronous.
901914

902-
- parameter breinLookup: An instance of BreinLookup.
903-
- parameter user: A plain object specifying information about the user to retrieve data for.
904-
- parameter dimension: An object (with an array) containing the names of the dimensions to lookup.
915+
- Parameter breinLookup: An instance of BreinLookup.
916+
- Parameter user: A plain object specifying information about the user to retrieve data for.
917+
- Parameter dimension: An object (with an array) containing the names of the dimensions to lookup.
905918
- Parameter success: A callback function that is invoked in case of success.
906919
- Parameter failure: A callback function that is invoked in case of an error.
907920

BreinifyApi/api/BreinifyManager.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
6060
}()
6161

6262
public func willRegisterPushNotification(_ shouldRegister: Bool) {
63-
self.shouldRegisterPushNotification = shouldRegister
63+
shouldRegisterPushNotification = shouldRegister
6464
}
6565

6666
public func hasRegisteredPushNotification() -> Bool {
67-
self.shouldRegisterPushNotification
67+
shouldRegisterPushNotification
6868
}
6969

7070
// Can't init the singleton
@@ -300,6 +300,7 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
300300
public func userNotificationCenter(_ center: UNUserNotificationCenter,
301301
didReceive response: UNNotificationResponse,
302302
withCompletionHandler completionHandler: @escaping () -> Void) {
303+
303304
BreinLogger.shared.log("Breinify UserNotification didReceive invoked with response: \(response)")
304305

305306
let campaignNotificationDic = getCampaignContent(response.notification.request.content.userInfo)
@@ -318,9 +319,15 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
318319
let campaignNotificationDic = getCampaignContent(userInfo)
319320
sendActivity(BreinActivityType.OPEN_PUSH_NOTIFICATION.rawValue, additionalActivityTagContent: campaignNotificationDic)
320321

322+
BreinLogger.shared.log("Breinify invoking handleIncomingNotificationContent from handleDidReceiveNotification method")
321323
handleIncomingNotificationContent(userInfo)
322324
}
323325

326+
@available(iOS 10, *)
327+
public func handleDidReceiveNotificationResponse(_ response: UNNotificationResponse) {
328+
BreinLogger.shared.log("Breinify handleDidReceiveNotificationResponse invoked with response: \(response)")
329+
}
330+
324331
public func handleWillPresentNotification(_ userInfo: [AnyHashable: Any]) {
325332

326333
BreinLogger.shared.log("Breinify handleWillPresentNotification invoked with notification: \(userInfo)")
@@ -462,7 +469,7 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
462469

463470
}
464471

465-
func registerPushNotifications() {
472+
public func registerPushNotifications() {
466473
BreinLogger.shared.log("Breinify registerPushNotifications invoked")
467474

468475
guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication else {

0 commit comments

Comments
 (0)