Skip to content

Commit 61ad43c

Browse files
authored
Merge pull request #1201 from OneSignal/user_model/alpha_1_round_4
[user model] alpha1 fixes (round 4)
2 parents d6c2ed1 + c0e7b8f commit 61ad43c

File tree

11 files changed

+65
-44
lines changed

11 files changed

+65
-44
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
105105
return YES;
106106
}
107107

108-
#define ONESIGNAL_APP_ID_DEFAULT @"1688d8f2-da7f-4815-8ee3-9d13788482c8"
109-
#define ONESIGNAL_APP_ID_KEY_FOR_TESTING @"1688d8f2-da7f-4815-8ee3-9d13788482c8"
108+
#define ONESIGNAL_APP_ID_DEFAULT @"YOUR_APP_ID_HERE"
109+
#define ONESIGNAL_APP_ID_KEY_FOR_TESTING @"YOUR_APP_ID_HERE"
110110

111111
+ (NSString*)getOneSignalAppId {
112112
NSString* userDefinedAppId = [[NSUserDefaults standardUserDefaults] objectForKey:ONESIGNAL_APP_ID_KEY_FOR_TESTING];

iOS_SDK/OneSignalDevApp/OneSignalDevApp/OneSignalDevApp.entitlements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</array>
1212
<key>com.apple.security.application-groups</key>
1313
<array>
14-
<string>group.com.onesignal.example.staging.onesignal</string>
14+
<string>group.com.onesignal.example.onesignal</string>
1515
</array>
1616
</dict>
1717
</plist>

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/OneSignalDevAppClip.entitlements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</array>
1212
<key>com.apple.developer.parent-application-identifiers</key>
1313
<array>
14-
<string>$(AppIdentifierPrefix)com.onesignal.example.staging</string>
14+
<string>$(AppIdentifierPrefix)com.onesignal.example</string>
1515
</array>
1616
</dict>
1717
</plist>

iOS_SDK/OneSignalDevApp/OneSignalExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@
745745
);
746746
MARKETING_VERSION = 1.4.4;
747747
OTHER_LDFLAGS = "-ObjC";
748-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging;
748+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
749749
PRODUCT_NAME = OneSignalExample;
750750
SUPPORTS_MACCATALYST = YES;
751751
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalDevApp/OneSignalExample-Bridging-Header.h";
@@ -776,7 +776,7 @@
776776
);
777777
MARKETING_VERSION = 1.4.4;
778778
OTHER_LDFLAGS = "-ObjC";
779-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging;
779+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
780780
PRODUCT_NAME = OneSignalExample;
781781
SUPPORTS_MACCATALYST = YES;
782782
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalDevApp/OneSignalExample-Bridging-Header.h";
@@ -804,7 +804,7 @@
804804
);
805805
MARKETING_VERSION = 1.4.4;
806806
OTHER_LDFLAGS = "-ObjC";
807-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.OneSignalNotificationServiceExtensionA;
807+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
808808
PRODUCT_NAME = "$(TARGET_NAME)";
809809
SKIP_INSTALL = YES;
810810
SUPPORTS_MACCATALYST = YES;
@@ -832,7 +832,7 @@
832832
);
833833
MARKETING_VERSION = 1.4.4;
834834
OTHER_LDFLAGS = "-ObjC";
835-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.OneSignalNotificationServiceExtensionA;
835+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
836836
PRODUCT_NAME = "$(TARGET_NAME)";
837837
SKIP_INSTALL = YES;
838838
SUPPORTS_MACCATALYST = YES;
@@ -877,7 +877,7 @@
877877
MARKETING_VERSION = 1.4.4;
878878
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
879879
MTL_FAST_MATH = YES;
880-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.Clip;
880+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.Clip;
881881
PRODUCT_NAME = OneSignalExampleClip;
882882
TARGETED_DEVICE_FAMILY = "1,2";
883883
};
@@ -915,7 +915,7 @@
915915
);
916916
MARKETING_VERSION = 1.4.4;
917917
MTL_FAST_MATH = YES;
918-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.Clip;
918+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.Clip;
919919
PRODUCT_NAME = OneSignalExampleClip;
920920
TARGETED_DEVICE_FAMILY = "1,2";
921921
};

iOS_SDK/OneSignalDevApp/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<dict>
55
<key>com.apple.security.application-groups</key>
66
<array>
7-
<string>group.com.onesignal.example.staging.onesignal</string>
7+
<string>group.com.onesignal.example.onesignal</string>
88
</array>
99
</dict>
1010
</plist>

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,6 @@ - (OSNotificationPermission)status {
159159
return OSNotificationPermissionNotDetermined;
160160
}
161161

162-
- (NSString*)statusAsString {
163-
switch(self.status) {
164-
case OSNotificationPermissionNotDetermined:
165-
return @"NotDetermined";
166-
case OSNotificationPermissionAuthorized:
167-
return @"Authorized";
168-
case OSNotificationPermissionDenied:
169-
return @"Denied";
170-
case OSNotificationPermissionProvisional:
171-
return @"Provisional";
172-
case OSNotificationPermissionEphemeral:
173-
return @"Ephemeral";
174-
}
175-
return @"NotDetermined";
176-
}
177-
178162
- (BOOL)compare:(OSPermissionStateInternal*)from {
179163
return self.accepted != from.accepted ||
180164
self.ephemeral != from.ephemeral ||
@@ -187,8 +171,8 @@ - (OSPermissionState *)getExternalState {
187171
}
188172

189173
- (NSString*)description {
190-
static NSString* format = @"<OSPermissionState: hasPrompted: %d, status: %@, provisional: %d>";
191-
return [NSString stringWithFormat:format, self.hasPrompted, self.statusAsString, self.provisional];
174+
static NSString* format = @"<OSPermissionStateInternal: hasPrompted: %d, status: %@, provisional: %d>";
175+
return [NSString stringWithFormat:format, self.hasPrompted, self.status, self.provisional];
192176
}
193177

194178

@@ -206,6 +190,27 @@ - (instancetype)initWithStatus:(OSNotificationPermission)status reachable:(BOOL)
206190
return self;
207191
}
208192

193+
- (NSString*)statusAsString {
194+
switch(self.status) {
195+
case OSNotificationPermissionNotDetermined:
196+
return @"NotDetermined";
197+
case OSNotificationPermissionAuthorized:
198+
return @"Authorized";
199+
case OSNotificationPermissionDenied:
200+
return @"Denied";
201+
case OSNotificationPermissionProvisional:
202+
return @"Provisional";
203+
case OSNotificationPermissionEphemeral:
204+
return @"Ephemeral";
205+
}
206+
return @"NotDetermined";
207+
}
208+
209+
- (NSString*)description {
210+
static NSString* format = @"<OSPermissionState: hasPrompted: %d, status: %@, provisional: %d>";
211+
return [NSString stringWithFormat:format, self.hasPrompted, self.statusAsString, self.provisional];
212+
}
213+
209214
- (NSDictionary*)toDictionary {
210215
return @{@"hasPrompted": @(self.hasPrompted),
211216
@"status": @(self.status),

iOS_SDK/OneSignalSDK/OneSignalOSCore/Source/OSModelStore.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ open class OSModelStore<TModel: OSModel>: NSObject {
4949
for model in self.models.values {
5050
model.changeNotifier.subscribe(self)
5151
}
52+
}
5253

53-
// register as user observer
54+
public func registerAsUserObserver() -> OSModelStore {
55+
// This method was taken out of the initializer as the push subscription model store should not be clearing its user defaults
5456
NotificationCenter.default.addObserver(self, selector: #selector(self.removeModelsFromUserDefaults),
5557
name: Notification.Name(OS_ON_USER_WILL_CHANGE), object: nil)
58+
return self
5659
}
5760

5861
deinit {

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSSubscriptionModel.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ public class OSPushSubscriptionState: NSObject {
4242
@objc public let token: String?
4343
@objc public let optedIn: Bool
4444

45+
@objc public override var description: String {
46+
return "<OSPushSubscriptionState: id: \(id ?? "nil"), token: \(token ?? "nil"), optedIn: \(optedIn)>"
47+
}
48+
4549
init(id: String?, token: String?, optedIn: Bool) {
4650
self.id = id
4751
self.token = token
4852
self.optedIn = optedIn
4953
}
5054

51-
func toDictionary() -> NSDictionary {
55+
@objc public func toDictionary() -> NSDictionary {
5256
let id = self.id ?? "nil"
5357
let token = self.token ?? "nil"
5458
return [
@@ -64,12 +68,16 @@ public class OSPushSubscriptionStateChanges: NSObject {
6468
@objc public let to: OSPushSubscriptionState
6569
@objc public let from: OSPushSubscriptionState
6670

71+
@objc public override var description: String {
72+
return "<OSPushSubscriptionStateChanges:\nfrom: \(self.from),\nto: \(self.to)\n>"
73+
}
74+
6775
init(to: OSPushSubscriptionState, from: OSPushSubscriptionState) {
6876
self.to = to
6977
self.from = from
7078
}
7179

72-
func toDictionary() -> NSDictionary {
80+
@objc public func toDictionary() -> NSDictionary {
7381
return ["from": from.toDictionary(), "to": to.toDictionary()]
7482
}
7583
}

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,20 +209,24 @@ class OSUserExecutor {
209209
static func executeIdentifyUserRequest(_ request: OSRequestIdentifyUser) {
210210
OneSignalClient.shared().execute(request) { _ in
211211
// the anonymous user has been identified, still need to Fetch User
212+
// TODO: Is the above true, do we need to Fetch? If the anon user is identified, then no user with this external_id existed, correct?
212213
fetchUser(aliasLabel: OS_EXTERNAL_ID, aliasId: request.aliasId, identityModel: request.identityModelToUpdate)
213214

214215
executePendingRequests() // TODO: Here or after fetch or after transfer?
215216

216-
} onFailure: { _ in
217-
// TODO: Actually account for error code when processing this failure response
217+
} onFailure: { error in
218218
// Returns 409 if any provided (label, id) pair exists on another User, so the SDK will switch to this user.
219-
// If 409:
220-
fetchUser(aliasLabel: OS_EXTERNAL_ID, aliasId: request.aliasId, identityModel: request.identityModelToUpdate)
221-
// TODO: Link ^ to the new user
222-
transferPushSubscriptionTo(aliasLabel: request.aliasLabel, aliasId: request.aliasId, retainPreviousUser: true) // update logic to determine flag
223-
executePendingRequests() // Here or after fetch or after transfer?
219+
if error?._code == 409 {
220+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "executeIdentifyUserRequest returned 409, failed due to alias already assigned to a different user. Now switch to this user.")
224221

225-
// If not 409, we retry, depending on what the error is?
222+
fetchUser(aliasLabel: OS_EXTERNAL_ID, aliasId: request.aliasId, identityModel: request.identityModelToUpdate)
223+
// TODO: Link ^ to the new user... what was this todo for?
224+
transferPushSubscriptionTo(aliasLabel: request.aliasLabel, aliasId: request.aliasId, retainPreviousUser: true) // update logic to determine flag
225+
executePendingRequests() // Here or after fetch or after transfer?
226+
} else {
227+
// If not 409, we retry, depending on what the error is?
228+
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "executeIdentifyUserRequest failed without returning a 409.")
229+
}
226230
}
227231
}
228232

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OneSignalUserManagerImpl.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
140140
return pushSubscriptionStateChangesObserver
141141
}
142142

143-
// has Identity, Properties, Subscription, and Push Subscription Model Stores
144-
let identityModelStore = OSModelStore<OSIdentityModel>(changeSubscription: OSEventProducer(), storeKey: OS_IDENTITY_MODEL_STORE_KEY)
145-
let propertiesModelStore = OSModelStore<OSPropertiesModel>(changeSubscription: OSEventProducer(), storeKey: OS_PROPERTIES_MODEL_STORE_KEY)
143+
// Model Stores
144+
let identityModelStore = OSModelStore<OSIdentityModel>(changeSubscription: OSEventProducer(), storeKey: OS_IDENTITY_MODEL_STORE_KEY).registerAsUserObserver()
145+
let propertiesModelStore = OSModelStore<OSPropertiesModel>(changeSubscription: OSEventProducer(), storeKey: OS_PROPERTIES_MODEL_STORE_KEY).registerAsUserObserver()
146146
// Holds email and sms subscription models
147-
let subscriptionModelStore = OSModelStore<OSSubscriptionModel>(changeSubscription: OSEventProducer(), storeKey: OS_SUBSCRIPTION_MODEL_STORE_KEY)
147+
let subscriptionModelStore = OSModelStore<OSSubscriptionModel>(changeSubscription: OSEventProducer(), storeKey: OS_SUBSCRIPTION_MODEL_STORE_KEY).registerAsUserObserver()
148148
// Holds a single push subscription model
149149
let pushSubscriptionModelStore = OSModelStore<OSSubscriptionModel>(changeSubscription: OSEventProducer(), storeKey: OS_PUSH_SUBSCRIPTION_MODEL_STORE_KEY)
150150

0 commit comments

Comments
 (0)