Skip to content

Commit b9b5d69

Browse files
authored
Merge pull request #1224 from OneSignal/5.0.0/beta_01_fixes
[5.0.0] Some more `beta-01` fixes to incorporate
2 parents 6ceb44c + d592eef commit b9b5d69

File tree

10 files changed

+51
-32
lines changed

10 files changed

+51
-32
lines changed

MIGRATION_GUIDE.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h1 align="center">OneSignal iOS SDK v5.0.0-alpha-02 Migration Guide</h1>
1+
<h1 align="center">OneSignal iOS SDK v5.0.0-beta-01 Migration Guide</h1>
22

33
![OneSignal Omni Channel Banner](https://user-images.githubusercontent.com/11739227/208625336-d28c8d01-a7cf-4f8e-9643-ac8d1948e9ae.png)
44

@@ -8,7 +8,7 @@ In this release, we are making a significant shift from a device-centered model
88

99
To facilitate this change, the `externalId` approach for identifying users is being replaced by the `login` and `logout` methods. In addition, the SDK now makes use of namespaces such as `User`, `Notifications`, and `InAppMessages` to better separate code.
1010

11-
The iOS SDK is making the jump from `v3` to `v5`, in order to align across OneSignal’s suite of client SDKs. This guide will walk you through the iOS SDK `5.0.0-alpha-02` changes as a result of this shift.
11+
The iOS SDK is making the jump from `v3` to `v5`, in order to align across OneSignal’s suite of client SDKs. This guide will walk you through the iOS SDK `5.0.0-beta-01` changes as a result of this shift.
1212

1313
# Overview
1414

@@ -60,10 +60,10 @@ As mentioned above, the iOS SDK is making the jump from `v3` to `v5`, in order t
6060
```
6161

6262
### Option 1. Swift Package Manager
63-
Update the version of the OneSignal-XCFramework your application uses to `5.0.0-alpha-02`. In addition, the Package Product name has been changed from `OneSignal` to `OneSignalFramework`. See [the existing installation instructions](https://documentation.onesignal.com/docs/swift-package-manager-setup).
63+
Update the version of the OneSignal-XCFramework your application uses to `5.0.0-beta-01`. In addition, the Package Product name has been changed from `OneSignal` to `OneSignalFramework`. See [the existing installation instructions](https://documentation.onesignal.com/docs/swift-package-manager-setup).
6464

6565
### Option 2. CocoaPods
66-
Update the version of the OneSignalXCFramework your application uses to `5.0.0-alpha-02`. Other than updating the import statement above, there are no additional changes needed to import the OneSignal SDK in your Xcode project. See [the existing installation instructions](https://documentation.onesignal.com/docs/ios-sdk-setup#step-3-import-the-onesignal-sdk-into-your-xcode-project).
66+
Update the version of the OneSignalXCFramework your application uses to `5.0.0-beta-01`. Other than updating the import statement above, there are no additional changes needed to import the OneSignal SDK in your Xcode project. See [the existing installation instructions](https://documentation.onesignal.com/docs/ios-sdk-setup#step-3-import-the-onesignal-sdk-into-your-xcode-project).
6767

6868
# API Changes
6969
## Namespaces
@@ -213,7 +213,7 @@ Email and/or SMS subscriptions can be added or removed via the following methods
213213

214214
# API Reference
215215

216-
Below is a comprehensive reference to the `5.0.0-alpha-02` OneSignal SDK.
216+
Below is a comprehensive reference to the `5.0.0-beta-01` OneSignal SDK.
217217

218218
## OneSignal
219219

@@ -727,14 +727,12 @@ The Debug namespace is accessible via `OneSignal.Debug` and provide access to de
727727
728728
# Limitations
729729

730-
- Recommend using only in development and staging environments for Alpha releases
731-
- Aliases will be available in a future release
730+
- Recommend using only in development and staging environments for Beta releases
732731
- Outcomes will be available in a future release
733-
- Users are deleted when the last Subscription (push, email, or sms) is removed
734732
- Any `User` namespace calls must be invoked **after** initialization. Example: `OneSignal.User.addTag("tag", "2")`
735733

736734
# Known issues
737735
- User properties may not update correctly when Subscriptions are transferred
738736
- Please report any issues you find with this
739737
- Identity Verification
740-
- We will be introducing JWT in a follow up Alpha or Beta release
738+
- We will be introducing JWT in a follow up Beta release

iOS_SDK/OneSignalSDK/OneSignalCore/Source/RemoteParameters/OSRemoteParamController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ @implementation OSRemoteParamController
3535

3636
static OSRemoteParamController *_sharedController;
3737
+ (OSRemoteParamController *)sharedController {
38+
if (!_sharedController)
39+
_sharedController = [OSRemoteParamController new];
3840
return _sharedController;
3941
}
4042

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ + (void)presentAppSettings {
337337
}
338338

339339
+ (void)clearAll {
340+
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
341+
// TODO: Determine if we also need to call clearBadgeCount
340342
[self clearBadgeCount:false];
341343
}
342344

@@ -369,9 +371,6 @@ + (BOOL)registerForAPNsToken {
369371

370372
+ (void)didRegisterForRemoteNotifications:(UIApplication *)app
371373
deviceToken:(NSData *)inDeviceToken {
372-
if ([OSPrivacyConsentController shouldLogMissingPrivacyConsentErrorWithMethodName:nil])
373-
return;
374-
375374
let parsedDeviceToken = [NSString hexStringFromData:inDeviceToken];
376375

377376
[OneSignalLog onesignalLog:ONE_S_LL_INFO message: [NSString stringWithFormat:@"Device Registered with Apple: %@", parsedDeviceToken]];

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSIdentityModel.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ class OSIdentityModel: OSModel {
8282
}
8383

8484
func removeAliases(_ labels: [String]) {
85-
var aliasesToSend: [String: String] = [:]
8685
for label in labels {
8786
self.aliases.removeValue(forKey: label)
88-
aliasesToSend[label] = ""
87+
self.set(property: "aliases", newValue: [label: ""])
8988
}
90-
self.set(property: "aliases", newValue: aliasesToSend)
9189
}
9290

9391
public override func hydrateModel(_ response: [String: Any]) {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSPropertiesModel.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,37 @@ struct OSPropertiesDeltas {
4545
}
4646
}
4747

48+
// Both lat and long must exist to be accepted by the server
49+
class OSLocationPoint: NSObject, NSCoding {
50+
let lat: Float
51+
let long: Float
52+
53+
init(lat: Float, long: Float) {
54+
self.lat = lat
55+
self.long = long
56+
}
57+
58+
public func encode(with coder: NSCoder) {
59+
coder.encode(lat, forKey: "lat")
60+
coder.encode(long, forKey: "long")
61+
}
62+
63+
public required init?(coder: NSCoder) {
64+
self.lat = coder.decodeFloat(forKey: "lat")
65+
self.long = coder.decodeFloat(forKey: "long")
66+
}
67+
}
68+
4869
class OSPropertiesModel: OSModel {
4970
var language: String? {
5071
didSet {
5172
self.set(property: "language", newValue: language)
5273
}
5374
}
5475

55-
var lat: Float? {
56-
didSet {
57-
self.set(property: "lat", newValue: lat)
58-
}
59-
}
60-
61-
var long: Float? {
76+
var location: OSLocationPoint? {
6277
didSet {
63-
self.set(property: "long", newValue: long)
78+
self.set(property: "location", newValue: location)
6479
}
6580
}
6681

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionOperationExecutor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OSSubscriptionOperationExecutor: OSOperationExecutor {
5959

6060
var requestQueue: [OSRequestCreateSubscription] = []
6161

62-
if var cachedAddRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestCreateSubscription] {
62+
if let cachedAddRequestQueue = OneSignalUserDefaults.initShared().getSavedCodeableData(forKey: OS_SUBSCRIPTION_EXECUTOR_ADD_REQUEST_QUEUE_KEY, defaultValue: []) as? [OSRequestCreateSubscription] {
6363
// Hook each uncached Request to the model in the store
6464
for request in cachedAddRequestQueue {
6565
// 1. Hook up the subscription model

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserInternalImpl.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ class OSUserInternalImpl: NSObject, OSUserInternal {
125125
func setLocation(lat: Float, long: Float) {
126126
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.User setLocation called with lat: \(lat) long: \(long)")
127127

128-
propertiesModel.lat = lat
129-
propertiesModel.long = long
128+
propertiesModel.location = OSLocationPoint(lat: lat, long: long)
130129
}
131130

132131
// MARK: - Language

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,8 +900,14 @@ class OSRequestUpdateProperties: OneSignalRequest, OSUserRequest {
900900
self.stringDescription = "OSRequestUpdateProperties with properties: \(properties) deltas: \(String(describing: deltas)) refreshDeviceMetadata: \(String(describing: refreshDeviceMetadata))"
901901
super.init()
902902

903+
var propertiesObject = properties
904+
if let location = propertiesObject["location"] as? OSLocationPoint {
905+
propertiesObject["lat"] = location.lat
906+
propertiesObject["long"] = location.long
907+
propertiesObject.removeValue(forKey: "location")
908+
}
903909
var params: [String: Any] = [:]
904-
params["properties"] = properties
910+
params["properties"] = propertiesObject
905911
params["refresh_device_metadata"] = refreshDeviceMetadata
906912
if let deltas = deltas {
907913
params["deltas"] = deltas

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,14 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
322322
}
323323

324324
/**
325-
The SDK needs to have a user at all times, so this method will create a new anonymous user.
325+
The SDK needs to have a user at all times, so this method will create a new anonymous user. If the current user is already anonymous, calling `logout` results in a no-op.
326326
*/
327327
@objc
328328
public func logout() {
329+
guard user.identityModel.externalId != nil else {
330+
OneSignalLog.onesignalLog(.LL_DEBUG, message: "OneSignal.User logout called, but the user is currently anonymous, so not logging out.")
331+
return
332+
}
329333
prepareForNewUser()
330334
_user = nil
331335
createUserIfNil()
@@ -670,9 +674,7 @@ extension OneSignalUserManagerImpl: OSUser {
670674
extension OneSignalUserManagerImpl: OSPushSubscription {
671675

672676
public func addObserver(_ observer: OSPushSubscriptionObserver) {
673-
guard !OneSignalConfigManager.shouldAwaitAppIdAndLogMissingPrivacyConsent(forMethod: "pushSubscription.addObserver") else {
674-
return
675-
}
677+
// This is a method in the User namespace that doesn't require privacy consent first
676678
self.pushSubscriptionStateChangesObserver.addObserver(observer)
677679
}
678680

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ + (void)startUserManager {
519519
}
520520

521521
+ (void)delayInitializationForPrivacyConsent {
522-
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Delayed initialization of the OneSignal SDK until the user provides privacy consent using the consentGranted() method"];
522+
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"Delayed initialization of the OneSignal SDK until the user provides privacy consent using the setPrivacyConsent() method"];
523523
delayedInitializationForPrivacyConsent = true;
524524
_delayedInitParameters = [[DelayedConsentInitializationParameters alloc] initWithLaunchOptions:launchOptions withAppId:appId];
525525
// Init was not successful, set appId back to nil

0 commit comments

Comments
 (0)