Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0.0] Push subscription related fixes (3) #1289

Merged
merged 21 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b7f070c
check for push subscription updates on new sessions
nan-li Aug 1, 2023
2fe55b3
Create the push sub model with a notification type
nan-li Aug 8, 2023
ea6c30c
Recreate a push subscription when we detect it is removed
nan-li Aug 7, 2023
7d7f13d
Add convenience accessor to the push subscription model
nan-li Aug 8, 2023
0d033d4
Allow the operation repo to be paused
nan-li Aug 8, 2023
ec27d63
On new session, user executor executes, and unpause operation repo
nan-li Aug 8, 2023
af02758
Add `timezone_id` to property model
nan-li Aug 8, 2023
0291cfa
[nits]
nan-li Aug 1, 2023
9641884
Always remove the window when an IAM is dismissed
emawby Aug 9, 2023
c34fc63
Ignore the second JS dismiss event
emawby Aug 10, 2023
f9ac55d
Define more background tasks
nan-li Aug 10, 2023
ff6c5fa
Background flush of operation repo
nan-li Aug 10, 2023
5a309b1
Background sending of session ending outcomes
nan-li Aug 10, 2023
c6cfcda
Update background sending session_time to user
nan-li Aug 10, 2023
2202fe7
[nits] logging
nan-li Aug 10, 2023
eb16f40
Don't handle addAlias conflict
nan-li Aug 10, 2023
cc22dee
Merge pull request #1300 from OneSignal/5.0.0/rehaul_background_tasks
emawby Aug 10, 2023
c2a9be3
Merge pull request #1294 from OneSignal/user_model/fix_in_app_display
emawby Aug 10, 2023
be65c89
Merge pull request #1290 from OneSignal/5.0.0/create_user_error
emawby Aug 10, 2023
1c8f185
[nits] rename Background Task Delegate to Handler
nan-li Aug 9, 2023
bef92f7
Merge branch '5.0.0/fix_session_influence' into 5.0.0/push_sub_fixes
nan-li Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class OSIdentityOperationExecutor: OSOperationExecutor {
return
}
// The subscription has been deleted along with the user, so remove the subscription_id but keep the same push subscription model
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModelStore.getModels()[OS_PUSH_SUBSCRIPTION_MODEL_KEY]?.subscriptionId = nil
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModel?.subscriptionId = nil
OneSignalUserManagerImpl.sharedInstance._logout()
} else if responseType == .conflict {
self.addRequestQueue.removeAll(where: { $0 == request})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class OSPropertyOperationExecutor: OSOperationExecutor {
return
}
// The subscription has been deleted along with the user, so remove the subscription_id but keep the same push subscription model
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModelStore.getModels()[OS_PUSH_SUBSCRIPTION_MODEL_KEY]?.subscriptionId = nil
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModel?.subscriptionId = nil
OneSignalUserManagerImpl.sharedInstance._logout()
} else if responseType != .retryable {
// Fail, no retry, remove from cache and queue
Expand Down
121 changes: 112 additions & 9 deletions iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,59 @@ class OSSubscriptionModel: OSModel {
}

// Properties for push subscription
var testType: Int?
let deviceOs = UIDevice.current.systemVersion
let sdk = ONESIGNAL_VERSION
let deviceModel: String? = OSDeviceUtils.getDeviceVariant()
let appVersion: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
let netType: Int? = OSNetworkingUtils.getNetType() as? Int
var testType: Int? {
didSet {
guard testType != oldValue else {
return
}
self.set(property: "testType", newValue: testType)
}
}

var deviceOs = UIDevice.current.systemVersion {
didSet {
guard deviceOs != oldValue else {
return
}
self.set(property: "deviceOs", newValue: deviceOs)
}
}

var sdk = ONESIGNAL_VERSION {
didSet {
guard sdk != oldValue else {
return
}
self.set(property: "sdk", newValue: sdk)
}
}

var deviceModel: String? = OSDeviceUtils.getDeviceVariant() {
didSet {
guard deviceModel != oldValue else {
return
}
self.set(property: "deviceModel", newValue: deviceModel)
}
}

var appVersion: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
didSet {
guard appVersion != oldValue else {
return
}
self.set(property: "appVersion", newValue: appVersion)
}
}

var netType: Int? = OSNetworkingUtils.getNetType() as? Int {
didSet {
guard netType != oldValue else {
return
}
self.set(property: "netType", newValue: netType)
}
}

// When a Subscription is initialized, it may not have a subscriptionId until a request to the backend is made.
init(type: OSSubscriptionType,
Expand All @@ -215,7 +262,7 @@ class OSSubscriptionModel: OSModel {
_reachable = reachable
_isDisabled = isDisabled

// Set test_type if subscription model is PUSH
// Set test_type if subscription model is PUSH, and update notificationTypes
if type == .push {
let releaseMode: OSUIApplicationReleaseMode = OneSignalMobileProvision.releaseMode()
// Workaround to unsure how to extract the Int value in 1 step...
Expand All @@ -228,6 +275,7 @@ class OSSubscriptionModel: OSModel {
if releaseMode == .UIApplicationReleaseWildcard {
self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseWildcard.rawValue
}
notificationTypes = Int(OSNotificationsManager.getNotificationTypes(_isDisabled))
}

super.init(changeNotifier: changeNotifier)
Expand All @@ -242,6 +290,11 @@ class OSSubscriptionModel: OSModel {
coder.encode(_isDisabled, forKey: "_isDisabled")
coder.encode(notificationTypes, forKey: "notificationTypes")
coder.encode(testType, forKey: "testType")
coder.encode(deviceOs, forKey: "deviceOs")
coder.encode(sdk, forKey: "sdk")
coder.encode(deviceModel, forKey: "deviceModel")
coder.encode(appVersion, forKey: "appVersion")
coder.encode(netType, forKey: "netType")
}

required init?(coder: NSCoder) {
Expand All @@ -259,6 +312,12 @@ class OSSubscriptionModel: OSModel {
self._isDisabled = coder.decodeBool(forKey: "_isDisabled")
self.notificationTypes = coder.decodeInteger(forKey: "notificationTypes")
self.testType = coder.decodeObject(forKey: "testType") as? Int
self.deviceOs = coder.decodeObject(forKey: "deviceOs") as? String ?? UIDevice.current.systemVersion
self.sdk = coder.decodeObject(forKey: "sdk") as? String ?? ONESIGNAL_VERSION
self.deviceModel = coder.decodeObject(forKey: "deviceModel") as? String
self.appVersion = coder.decodeObject(forKey: "appVersion") as? String
self.netType = coder.decodeObject(forKey: "netType") as? Int

super.init(coder: coder)
}

Expand Down Expand Up @@ -290,6 +349,26 @@ class OSSubscriptionModel: OSModel {
}
}
}

// Using snake_case so we can use this in request bodies
public func jsonRepresentation() -> [String: Any] {
var json: [String: Any] = [:]
json["id"] = self.subscriptionId
json["type"] = self.type.rawValue
json["token"] = self.address
json["enabled"] = self.enabled
json["test_type"] = self.testType
json["device_os"] = self.deviceOs
json["sdk"] = self.sdk
json["device_model"] = self.deviceModel
json["app_version"] = self.appVersion
json["net_type"] = self.netType
// notificationTypes defaults to -1 instead of nil, don't send if it's -1
if self.notificationTypes != -1 {
json["notification_types"] = self.notificationTypes
}
return json
}
}

// Push Subscription related
Expand Down Expand Up @@ -317,15 +396,39 @@ extension OSSubscriptionModel {
func updateNotificationTypes() {
notificationTypes = Int(OSNotificationsManager.getNotificationTypes(_isDisabled))
}


func updateTestType() {
let releaseMode: OSUIApplicationReleaseMode = OneSignalMobileProvision.releaseMode()
// Workaround to unsure how to extract the Int value in 1 step...
if releaseMode == .UIApplicationReleaseDev {
self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseDev.rawValue
}
if releaseMode == .UIApplicationReleaseAdHoc {
self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseAdHoc.rawValue
}
if releaseMode == .UIApplicationReleaseWildcard {
self.testType = OSUIApplicationReleaseMode.UIApplicationReleaseWildcard.rawValue
}
}

func update() {
updateTestType()
deviceOs = UIDevice.current.systemVersion
sdk = ONESIGNAL_VERSION
deviceModel = OSDeviceUtils.getDeviceVariant()
appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
netType = OSNetworkingUtils.getNetType() as? Int
// sdkType ??
// isRooted ??
}

enum OSPushPropertyChanged {
case subscriptionId(String?)
case reachable(Bool)
case isDisabled(Bool)
case address(String?)
}

// TODO: Fix when isDisabled is set to true, the push subscription observer is not fired due to known bug.
func firePushSubscriptionChanged(_ changedProperty: OSPushPropertyChanged) {
var prevIsOptedIn = true
var prevIsEnabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
processRequestQueue()
}

// Bypasses the operation repo to create a push subscription request
func createPushSubscription(subscriptionModel: OSSubscriptionModel, identityModel: OSIdentityModel) {
let request = OSRequestCreateSubscription(subscriptionModel: subscriptionModel, identityModel: identityModel)
addRequestQueue.append(request)
OneSignalUserDefaults.initShared().saveCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY, withValue: self.addRequestQueue)
}

func processRequestQueue() {
let requestQueue: [OneSignalRequest] = addRequestQueue + removeRequestQueue + updateRequestQueue

Expand Down Expand Up @@ -257,7 +264,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
return
}
// The subscription has been deleted along with the user, so remove the subscription_id but keep the same push subscription model
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModelStore.getModels()[OS_PUSH_SUBSCRIPTION_MODEL_KEY]?.subscriptionId = nil
OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModel?.subscriptionId = nil
OneSignalUserManagerImpl.sharedInstance._logout()
} else if responseType != .retryable {
// Fail, no retry, remove from cache and queue
Expand Down
Loading
Loading