Skip to content

Commit

Permalink
[Feat] sopt-makers#354 - 푸시 알림 동의 여부를 Amplitude User Properties에 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Jan 21, 2024
1 parent b1af15e commit 8a34513
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ public extension Amplitude {

AmplitudeInstance.shared.track(eventType: eventType, eventProperties: eventProperties, options: nil)
}

func addPushNotificationAuthorizationIdentity(isAuthorized: Bool) {
let identify = Identify()
let key: AmplitudeUserPropertyKey = .notificationAuthorized
identify.set(property: key.rawValue, value: isAuthorized)
identify.unset(property: "testProperty")

AmplitudeInstance.shared.identify(identify: identify)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AmplitudeUserPropertyKey.swift
// Core
//
// Created by sejin on 1/21/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Foundation

public enum AmplitudeUserPropertyKey: String {
case notificationAuthorized = "notification_authorized"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension AppLifecycleAdapter {
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] _ in
self?.reissureTokens()
self?.checkNotificationSetting()
}).store(in: self.cancelBag)
}

Expand All @@ -44,4 +45,11 @@ extension AppLifecycleAdapter {

self.authService.reissuance { _ in }
}

private func checkNotificationSetting() {
UNUserNotificationCenter.current().getNotificationSettings { setting in
let isNotificationAuthorized = setting.authorizationStatus == .authorized
AmplitudeInstance.shared.addPushNotificationAuthorizationIdentity(isAuthorized: isNotificationAuthorized)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,8 @@ extension MainViewModel {
// APNS 권한 허용 확인
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { granted, error in
if let error = error {
print(error)
}

if let error = error { print(error) }
AmplitudeInstance.shared.addPushNotificationAuthorizationIdentity(isAuthorized: granted)
print("APNs-알림 권한 허용 유무 \(granted)")

if granted {
Expand Down

0 comments on commit 8a34513

Please sign in to comment.