Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

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

+ (NSString*)getOneSignalAppId {
NSString* userDefinedAppId = [[NSUserDefaults standardUserDefaults] objectForKey:ONESIGNAL_APP_ID_KEY_FOR_TESTING];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</array>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.onesignal.example.staging.onesignal</string>
<string>group.com.onesignal.example.onesignal</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</array>
<key>com.apple.developer.parent-application-identifiers</key>
<array>
<string>$(AppIdentifierPrefix)com.onesignal.example.staging</string>
<string>$(AppIdentifierPrefix)com.onesignal.example</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@
);
MARKETING_VERSION = 1.4.4;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
PRODUCT_NAME = OneSignalExample;
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalDevApp/OneSignalExample-Bridging-Header.h";
Expand Down Expand Up @@ -776,7 +776,7 @@
);
MARKETING_VERSION = 1.4.4;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
PRODUCT_NAME = OneSignalExample;
SUPPORTS_MACCATALYST = YES;
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalDevApp/OneSignalExample-Bridging-Header.h";
Expand Down Expand Up @@ -804,7 +804,7 @@
);
MARKETING_VERSION = 1.4.4;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.OneSignalNotificationServiceExtensionA;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = YES;
Expand Down Expand Up @@ -832,7 +832,7 @@
);
MARKETING_VERSION = 1.4.4;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.OneSignalNotificationServiceExtensionA;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SUPPORTS_MACCATALYST = YES;
Expand Down Expand Up @@ -877,7 +877,7 @@
MARKETING_VERSION = 1.4.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.Clip;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.Clip;
PRODUCT_NAME = OneSignalExampleClip;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -915,7 +915,7 @@
);
MARKETING_VERSION = 1.4.4;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.Clip;
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.Clip;
PRODUCT_NAME = OneSignalExampleClip;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.com.onesignal.example.staging.onesignal</string>
<string>group.com.onesignal.example.onesignal</string>
</array>
</dict>
</plist>
41 changes: 23 additions & 18 deletions iOS_SDK/OneSignalSDK/OneSignalNotifications/OSPermission.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,6 @@ - (OSNotificationPermission)status {
return OSNotificationPermissionNotDetermined;
}

- (NSString*)statusAsString {
switch(self.status) {
case OSNotificationPermissionNotDetermined:
return @"NotDetermined";
case OSNotificationPermissionAuthorized:
return @"Authorized";
case OSNotificationPermissionDenied:
return @"Denied";
case OSNotificationPermissionProvisional:
return @"Provisional";
case OSNotificationPermissionEphemeral:
return @"Ephemeral";
}
return @"NotDetermined";
}

- (BOOL)compare:(OSPermissionStateInternal*)from {
return self.accepted != from.accepted ||
self.ephemeral != from.ephemeral ||
Expand All @@ -187,8 +171,8 @@ - (OSPermissionState *)getExternalState {
}

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


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

- (NSString*)statusAsString {
switch(self.status) {
case OSNotificationPermissionNotDetermined:
return @"NotDetermined";
case OSNotificationPermissionAuthorized:
return @"Authorized";
case OSNotificationPermissionDenied:
return @"Denied";
case OSNotificationPermissionProvisional:
return @"Provisional";
case OSNotificationPermissionEphemeral:
return @"Ephemeral";
}
return @"NotDetermined";
}

- (NSString*)description {
static NSString* format = @"<OSPermissionState: hasPrompted: %d, status: %@, provisional: %d>";
return [NSString stringWithFormat:format, self.hasPrompted, self.statusAsString, self.provisional];
}

- (NSDictionary*)toDictionary {
return @{@"hasPrompted": @(self.hasPrompted),
@"status": @(self.status),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ open class OSModelStore<TModel: OSModel>: NSObject {
for model in self.models.values {
model.changeNotifier.subscribe(self)
}
}

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

deinit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ public class OSPushSubscriptionState: NSObject {
@objc public let token: String?
@objc public let optedIn: Bool

@objc public override var description: String {
return "<OSPushSubscriptionState: id: \(id ?? "nil"), token: \(token ?? "nil"), optedIn: \(optedIn)>"
}

init(id: String?, token: String?, optedIn: Bool) {
self.id = id
self.token = token
self.optedIn = optedIn
}

func toDictionary() -> NSDictionary {
@objc public func toDictionary() -> NSDictionary {
let id = self.id ?? "nil"
let token = self.token ?? "nil"
return [
Expand All @@ -64,12 +68,16 @@ public class OSPushSubscriptionStateChanges: NSObject {
@objc public let to: OSPushSubscriptionState
@objc public let from: OSPushSubscriptionState

@objc public override var description: String {
return "<OSPushSubscriptionStateChanges:\nfrom: \(self.from),\nto: \(self.to)\n>"
}

init(to: OSPushSubscriptionState, from: OSPushSubscriptionState) {
self.to = to
self.from = from
}

func toDictionary() -> NSDictionary {
@objc public func toDictionary() -> NSDictionary {
return ["from": from.toDictionary(), "to": to.toDictionary()]
}
}
Expand Down
20 changes: 12 additions & 8 deletions iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,24 @@ class OSUserExecutor {
static func executeIdentifyUserRequest(_ request: OSRequestIdentifyUser) {
OneSignalClient.shared().execute(request) { _ in
// the anonymous user has been identified, still need to Fetch User
// 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?
fetchUser(aliasLabel: OS_EXTERNAL_ID, aliasId: request.aliasId, identityModel: request.identityModelToUpdate)

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ public class OneSignalUserManagerImpl: NSObject, OneSignalUserManager {
return pushSubscriptionStateChangesObserver
}

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

Expand Down
1 change: 1 addition & 0 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ + (void)setLaunchOptions:(nullable NSDictionary*)newLaunchOptions {
[OSNotificationsManager setColdStartFromTapOnNotification:YES];
}

// TODO: Should this be in the InAppMessages namespace?
+ (void)setLaunchURLsInApp:(BOOL)launchInApp {
NSMutableDictionary *newSettings = [[NSMutableDictionary alloc] initWithDictionary:appSettings];
newSettings[kOSSettingsKeyInAppLaunchURL] = launchInApp ? @true : @false;
Expand Down