diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 30b535fbd..e29b8d1c0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -228,7 +228,7 @@ + (BOOL)permission { } + (BOOL)canRequestPermission { - return !self.currentPermissionState.hasPrompted; + return !self.currentPermissionState.answeredPrompt; } + (void)requestPermission:(OSUserResponseBlock)block { @@ -423,14 +423,14 @@ + (void)setSubscriptionErrorStatus:(int)errorType { // onOSPermissionChanged should only fire if something changed. + (void)addPermissionObserver:(NSObject*)observer { - [_permissionStateChangesObserver addObserver:observer]; + [self.permissionStateChangesObserver addObserver:observer]; if ([self.currentPermissionState compare:self.lastPermissionState]) [OSPermissionChangedInternalObserver fireChangesObserver:self.currentPermissionState]; } + (void)removePermissionObserver:(NSObject*)observer { - [_permissionStateChangesObserver removeObserver:observer]; + [self.permissionStateChangesObserver removeObserver:observer]; } // User just responed to the iOS native notification permission prompt. diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m index 931b33424..f6dd120a0 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m @@ -237,7 +237,7 @@ + (void)fireChangesObserver:(OSPermissionStateInternal*)state { // Update the push subscription's _accepted property // TODO: This can be called before the User Manager has set itself as the delegate if (OSNotificationsManager.delegate && [OSNotificationsManager.delegate respondsToSelector:@selector(setAccepted:)]) { - [OSNotificationsManager.delegate setAccepted:state.accepted]; + [OSNotificationsManager.delegate setAccepted:state.reachable]; } } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift index 5f7ef1a5a..cba955012 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift @@ -162,9 +162,13 @@ class OSSubscriptionModel: OSModel { self.set(property: "notificationTypes", newValue: notificationTypes) } } + // swiftlint:disable identifier_name - // This is set by the permission state changing - // Defaults to true for email & SMS, defaults to false for push + /** + This is set by the permission state changing. + Defaults to true for email & SMS, defaults to false for push. + Note that this property reflects the `reachable` property of a permission state. As provisional permission is considered to be `optedIn` and `enabled`. + */ var _accepted: Bool { didSet { guard self.type == .push && _accepted != oldValue else { @@ -191,6 +195,8 @@ class OSSubscriptionModel: OSModel { 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 // When a Subscription is initialized, it may not have a subscriptionId until a request to the backend is made. init(type: OSSubscriptionType, @@ -231,6 +237,7 @@ class OSSubscriptionModel: OSModel { coder.encode(_accepted, forKey: "_accepted") coder.encode(_isDisabled, forKey: "_isDisabled") coder.encode(notificationTypes, forKey: "notificationTypes") + coder.encode(testType, forKey: "testType") } required init?(coder: NSCoder) { @@ -247,6 +254,7 @@ class OSSubscriptionModel: OSModel { self._accepted = coder.decodeBool(forKey: "_accepted") self._isDisabled = coder.decodeBool(forKey: "_isDisabled") self.notificationTypes = coder.decodeInteger(forKey: "notificationTypes") + self.testType = coder.decodeObject(forKey: "testType") as? Int super.init(coder: coder) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift index 32e3dc164..1017ea1a6 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift @@ -331,12 +331,12 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest { pushSubscriptionObject["type"] = pushSubscriptionModel.type.rawValue pushSubscriptionObject["token"] = pushSubscriptionModel.address pushSubscriptionObject["enabled"] = pushSubscriptionModel.enabled - pushSubscriptionObject["test_type"] = pushSubscriptionModel.testType pushSubscriptionObject["device_os"] = pushSubscriptionModel.deviceOs pushSubscriptionObject["sdk"] = pushSubscriptionModel.sdk pushSubscriptionObject["device_model"] = pushSubscriptionModel.deviceModel - + pushSubscriptionObject["app_version"] = pushSubscriptionModel.appVersion + pushSubscriptionObject["net_type"] = pushSubscriptionModel.netType // notificationTypes defaults to -1 instead of nil, don't send if it's -1 if pushSubscriptionModel.notificationTypes != -1 { pushSubscriptionObject["notification_types"] = pushSubscriptionModel.notificationTypes