Skip to content

Commit afedcb4

Browse files
authored
Merge pull request #1216 from OneSignal/5.0.0/fill_out_subscription_object
[5.0.0] Fill out subscription object and make subscription/permission fixes
2 parents 78e9f05 + d45a79b commit afedcb4

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ + (BOOL)permission {
228228
}
229229

230230
+ (BOOL)canRequestPermission {
231-
return !self.currentPermissionState.hasPrompted;
231+
return !self.currentPermissionState.answeredPrompt;
232232
}
233233

234234
+ (void)requestPermission:(OSUserResponseBlock)block {
@@ -423,14 +423,14 @@ + (void)setSubscriptionErrorStatus:(int)errorType {
423423

424424
// onOSPermissionChanged should only fire if something changed.
425425
+ (void)addPermissionObserver:(NSObject<OSPermissionObserver>*)observer {
426-
[_permissionStateChangesObserver addObserver:observer];
426+
[self.permissionStateChangesObserver addObserver:observer];
427427

428428
if ([self.currentPermissionState compare:self.lastPermissionState])
429429
[OSPermissionChangedInternalObserver fireChangesObserver:self.currentPermissionState];
430430
}
431431

432432
+ (void)removePermissionObserver:(NSObject<OSPermissionObserver>*)observer {
433-
[_permissionStateChangesObserver removeObserver:observer];
433+
[self.permissionStateChangesObserver removeObserver:observer];
434434
}
435435

436436
// User just responed to the iOS native notification permission prompt.

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ + (void)fireChangesObserver:(OSPermissionStateInternal*)state {
237237
// Update the push subscription's _accepted property
238238
// TODO: This can be called before the User Manager has set itself as the delegate
239239
if (OSNotificationsManager.delegate && [OSNotificationsManager.delegate respondsToSelector:@selector(setAccepted:)]) {
240-
[OSNotificationsManager.delegate setAccepted:state.accepted];
240+
[OSNotificationsManager.delegate setAccepted:state.reachable];
241241
}
242242
}
243243

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ class OSSubscriptionModel: OSModel {
162162
self.set(property: "notificationTypes", newValue: notificationTypes)
163163
}
164164
}
165+
165166
// swiftlint:disable identifier_name
166-
// This is set by the permission state changing
167-
// Defaults to true for email & SMS, defaults to false for push
167+
/**
168+
This is set by the permission state changing.
169+
Defaults to true for email & SMS, defaults to false for push.
170+
Note that this property reflects the `reachable` property of a permission state. As provisional permission is considered to be `optedIn` and `enabled`.
171+
*/
168172
var _accepted: Bool {
169173
didSet {
170174
guard self.type == .push && _accepted != oldValue else {
@@ -191,6 +195,8 @@ class OSSubscriptionModel: OSModel {
191195
let deviceOs = UIDevice.current.systemVersion
192196
let sdk = ONESIGNAL_VERSION
193197
let deviceModel: String? = OSDeviceUtils.getDeviceVariant()
198+
let appVersion: String? = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
199+
let netType: Int? = OSNetworkingUtils.getNetType() as? Int
194200

195201
// When a Subscription is initialized, it may not have a subscriptionId until a request to the backend is made.
196202
init(type: OSSubscriptionType,
@@ -231,6 +237,7 @@ class OSSubscriptionModel: OSModel {
231237
coder.encode(_accepted, forKey: "_accepted")
232238
coder.encode(_isDisabled, forKey: "_isDisabled")
233239
coder.encode(notificationTypes, forKey: "notificationTypes")
240+
coder.encode(testType, forKey: "testType")
234241
}
235242

236243
required init?(coder: NSCoder) {
@@ -247,6 +254,7 @@ class OSSubscriptionModel: OSModel {
247254
self._accepted = coder.decodeBool(forKey: "_accepted")
248255
self._isDisabled = coder.decodeBool(forKey: "_isDisabled")
249256
self.notificationTypes = coder.decodeInteger(forKey: "notificationTypes")
257+
self.testType = coder.decodeObject(forKey: "testType") as? Int
250258
super.init(coder: coder)
251259
}
252260

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,12 @@ class OSRequestCreateUser: OneSignalRequest, OSUserRequest {
331331
pushSubscriptionObject["type"] = pushSubscriptionModel.type.rawValue
332332
pushSubscriptionObject["token"] = pushSubscriptionModel.address
333333
pushSubscriptionObject["enabled"] = pushSubscriptionModel.enabled
334-
335334
pushSubscriptionObject["test_type"] = pushSubscriptionModel.testType
336335
pushSubscriptionObject["device_os"] = pushSubscriptionModel.deviceOs
337336
pushSubscriptionObject["sdk"] = pushSubscriptionModel.sdk
338337
pushSubscriptionObject["device_model"] = pushSubscriptionModel.deviceModel
339-
338+
pushSubscriptionObject["app_version"] = pushSubscriptionModel.appVersion
339+
pushSubscriptionObject["net_type"] = pushSubscriptionModel.netType
340340
// notificationTypes defaults to -1 instead of nil, don't send if it's -1
341341
if pushSubscriptionModel.notificationTypes != -1 {
342342
pushSubscriptionObject["notification_types"] = pushSubscriptionModel.notificationTypes

0 commit comments

Comments
 (0)