Skip to content

Commit

Permalink
More logs
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Nov 20, 2023
1 parent fb8c8a8 commit d4417ab
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions Example/PNDecryptionService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,36 @@ class NotificationService: UNNotificationServiceExtension {
self.contentHandler = contentHandler
self.bestAttemptContent = request.content

log("APNS: didReceive(_:) fired")

if let content = bestAttemptContent,
let topic = content.userInfo["topic"] as? String,
let ciphertext = content.userInfo["blob"] as? String {

log("APNS: topic and blob found")

do {
let service = NotifyDecryptionService(groupIdentifier: "group.com.walletconnect.sdk")
let (pushMessage, account) = try service.decryptMessage(topic: topic, ciphertext: ciphertext)

log("APNS: message decrypted", account: account, topic: topic, message: pushMessage)

let updatedContent = try handle(content: content, pushMessage: pushMessage, topic: topic)

let mutableContent = updatedContent.mutableCopy() as! UNMutableNotificationContent
mutableContent.title = pushMessage.title
mutableContent.subtitle = pushMessage.url
mutableContent.body = pushMessage.body

logMessage(message: pushMessage, account: account, topic: topic)
log("APNS: message handled", account: account, topic: topic, message: pushMessage)

contentHandler(mutableContent)

log("APNS: content handled", account: account, topic: topic, message: pushMessage)
}
catch {
log("APNS: error: \(error.localizedDescription)")

let mutableContent = content.mutableCopy() as! UNMutableNotificationContent
mutableContent.title = "Error"
mutableContent.body = error.localizedDescription
Expand Down Expand Up @@ -117,7 +128,7 @@ private extension NotificationService {
return fileURL
}

func logMessage(message: NotifyMessage, account: Account, topic: String) {
func log(_ event: String, account: Account? = nil, topic: String? = nil, message: NotifyMessage? = nil) {
let keychain = GroupKeychainStorage(serviceIdentifier: "group.com.walletconnect.sdk")

guard let clientId: String = try? keychain.read(key: "clientId") else {
Expand All @@ -128,20 +139,23 @@ private extension NotificationService {

Mixpanel.initialize(token: token, trackAutomaticEvents: true)

let mixpanel = Mixpanel.mainInstance()
mixpanel.alias = account.absoluteString
mixpanel.identify(distinctId: clientId)
mixpanel.people.set(properties: ["$name": account.absoluteString, "account": account.absoluteString])
if let account {
let mixpanel = Mixpanel.mainInstance()
mixpanel.alias = account.absoluteString
mixpanel.identify(distinctId: clientId)
mixpanel.people.set(properties: ["$name": account.absoluteString, "account": account.absoluteString])
}

Mixpanel.mainInstance().track(
event: "APNS message received",
event: event,
properties: [
"title": message.title,
"body": message.body,
"icon": message.icon,
"url": message.url,
"type": message.type,
"topic": topic
"title": message?.title,
"body": message?.body,
"icon": message?.icon,
"url": message?.url,
"type": message?.type,
"topic": topic,
"source": "NotificationService"
]
)
}
Expand Down

0 comments on commit d4417ab

Please sign in to comment.