Skip to content

Commit

Permalink
improved activity timing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoRecchioni committed Jun 14, 2021
1 parent 50b71ec commit ac4ce41
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion BreinifyApi.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'BreinifyApi'
s.version = '2.0.13'
s.version = '2.0.14'
s.summary = 'Breinify´s DigitalDNA API puts dynamic behavior-based, people-driven data right at your fingertips'
s.description = 'Breinify´s DigitalDNA API puts dynamic behavior-based, people-driven data right at your fingertips. We believe that in many situations, a critical component of a great user experience is personalization. With all the data available on the web it should be easy to provide a unique experience to every visitor, and yet, sometimes you may find yourself wondering why it is so difficult.'
s.homepage = 'https://github.com/Breinify/brein-api-library-ios'
Expand Down
49 changes: 27 additions & 22 deletions BreinifyApi/api/BreinifyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
BreinLogger.shared.log("Breinify UserNotification willPresent invoked with notification: \(notification)")

// due to a possible URLSession connection time out we wait half a second to send a message
// DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) { [self] in
// let campaignNotificationDic = getCampaignContent(notification.request.content.userInfo)
// sendActivity(BreinActivityType.RECEIVED_PUSH_NOTIFICATION.rawValue, additionalActivityTagContent: campaignNotificationDic)
// }
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5) { [self] in
let campaignNotificationDic = getCampaignContent(notification.request.content.userInfo)
sendActivity(BreinActivityType.RECEIVED_PUSH_NOTIFICATION.rawValue, additionalActivityTagContent: campaignNotificationDic)
}

completionHandler([.alert, .badge, .sound])
}
Expand Down Expand Up @@ -515,7 +515,7 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
BreinLogger.shared.log("Breinify didReceiveRemoteNotification called with notification: \(notification)")

// due to a possible URLSession connection time out we wait half a second to send a message
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) { [self] in
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5) { [self] in
let campaignNotificationDic = getCampaignContent(notification)
sendActivity(BreinActivityType.RECEIVED_PUSH_NOTIFICATION.rawValue, additionalActivityTagContent: campaignNotificationDic)
}
Expand All @@ -533,31 +533,36 @@ open class BreinifyManager: NSObject, UNUserNotificationCenterDelegate {
return nil
}

var retVal: Dictionary<String, Any> = [:]
let notiDic = BreinUtil.convertToDictionary(text: prettyPrinted)
notiDic?.forEach {
let key = ($0)
if key.contains("breinify") {
BreinLogger.shared.log("Breinify Tag detected in notification")
if let innerValue = ($1) as? String {
if innerValue != nil {
let innerDic = BreinUtil.convertToDictionary(text: innerValue)
innerDic?.forEach {
let key = $0
let val = $1
if key.contains("campaign") {
if let campaignDic = val as? Dictionary<String, Any> {
retVal = campaignDic
BreinLogger.shared.log("Breinify Campaign content is \(campaignDic)")
do {
var retVal: Dictionary<String, Any> = [:]
let notiDic = BreinUtil.convertToDictionary(text: prettyPrinted)
notiDic?.forEach {
let key = ($0)
if key.contains("breinify") {
BreinLogger.shared.log("Breinify Tag detected in notification")
if let innerValue = ($1) as? String {
if innerValue != nil {
let innerDic = BreinUtil.convertToDictionary(text: innerValue)
innerDic?.forEach {
let key = $0
let val = $1
if key.contains("campaign") {
if let campaignDic = val as? Dictionary<String, Any> {
retVal = campaignDic
BreinLogger.shared.log("Breinify Campaign content is \(campaignDic)")
}
}
}
}
}
}
}

return retVal
} catch {
return nil
}

return retVal
}

public func didFailToRegisterForRemoteNotificationsWithError(_ error: Error) {
Expand Down

0 comments on commit ac4ce41

Please sign in to comment.