Skip to content

Commit

Permalink
Merge pull request #1275 from OneSignal/user_model/remove_launch_urls…
Browse files Browse the repository at this point in the history
…_in_app

[User model] Remove launch urls in app
  • Loading branch information
emawby authored and nan-li committed Oct 30, 2023
2 parents 828a141 + cd39dab commit d695d51
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 117 deletions.
1 change: 0 additions & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
_notificationDelegate = [OneSignalNotificationCenterDelegate new];

// OneSignal Init with app id and lauch options
[OneSignal setLaunchURLsInApp:YES];
[OneSignal setProvidesNotificationSettingsView:NO];

[OneSignal.InAppMessages addLifecycleListener:self];
Expand Down
1 change: 0 additions & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
_notificationDelegate = [OneSignalNotificationCenterDelegate new];

// OneSignal Init with app id and lauch options
[OneSignal setLaunchURLsInApp:YES];
[OneSignal setProvidesNotificationSettingsView:NO];
[OneSignal initialize:[AppDelegate getOneSignalAppId] withLaunchOptions:launchOptions];

Expand Down
32 changes: 12 additions & 20 deletions iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
DE69E1A0282ED8060090BB3D /* OneSignalUser.h in Headers */ = {isa = PBXBuildFile; fileRef = DE69E19D282ED8060090BB3D /* OneSignalUser.h */; settings = {ATTRIBUTES = (Public, ); }; };
DE69E1AC282ED87A0090BB3D /* OneSignalUserManagerImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE69E1AA282ED8790090BB3D /* OneSignalUserManagerImpl.swift */; };
DE69E1B2282ED9430090BB3D /* OneSignalUser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DE69E19B282ED8060090BB3D /* OneSignalUser.framework */; };
DE70EB922A5CACF5003166D3 /* OneSignalWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF7847F29146BBE00A1F3A5 /* OneSignalWebViewManager.m */; };
DE70EB932A5CACF5003166D3 /* OneSignalWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF7847B29146B2700A1F3A5 /* OneSignalWebView.m */; };
DE70EB942A5CAD70003166D3 /* OneSignalWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = DEF7847C29146B2700A1F3A5 /* OneSignalWebView.h */; };
DE70EB952A5CAD77003166D3 /* OneSignalWebViewManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DEF7848129146BD100A1F3A5 /* OneSignalWebViewManager.h */; };
DE7D17EA27026B95002D3A5D /* OneSignalCore.docc in Sources */ = {isa = PBXBuildFile; fileRef = DE7D17E927026B95002D3A5D /* OneSignalCore.docc */; };
DE7D17EB27026B95002D3A5D /* OneSignalCore.h in Headers */ = {isa = PBXBuildFile; fileRef = DE7D17E827026B95002D3A5D /* OneSignalCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
DE7D17FD27026BA3002D3A5D /* OneSignalExtension.docc in Sources */ = {isa = PBXBuildFile; fileRef = DE7D17FC27026BA3002D3A5D /* OneSignalExtension.docc */; };
Expand Down Expand Up @@ -454,10 +458,6 @@
DEF7847229132AA700A1F3A5 /* OSNotification+OneSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = DEF7847029132AA700A1F3A5 /* OSNotification+OneSignal.h */; settings = {ATTRIBUTES = (Public, ); }; };
DEF7847329132AA700A1F3A5 /* OSNotification+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF7847129132AA700A1F3A5 /* OSNotification+OneSignal.m */; };
DEF784792914667A00A1F3A5 /* NSDateFormatter+OneSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = DE9877292591654600DE07D5 /* NSDateFormatter+OneSignal.h */; settings = {ATTRIBUTES = (Public, ); }; };
DEF7847D29146B2700A1F3A5 /* OneSignalWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF7847B29146B2700A1F3A5 /* OneSignalWebView.m */; };
DEF7847E29146B2700A1F3A5 /* OneSignalWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = DEF7847C29146B2700A1F3A5 /* OneSignalWebView.h */; settings = {ATTRIBUTES = (Public, ); }; };
DEF7848029146BBE00A1F3A5 /* OneSignalWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF7847F29146BBE00A1F3A5 /* OneSignalWebViewManager.m */; };
DEF7848229146BD100A1F3A5 /* OneSignalWebViewManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DEF7848129146BD100A1F3A5 /* OneSignalWebViewManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
DEF7848429146DA700A1F3A5 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEF7848329146DA700A1F3A5 /* WebKit.framework */; };
DEF7848A291471DA00A1F3A5 /* UNUserNotificationCenter+OneSignalNotifications.m in Sources */ = {isa = PBXBuildFile; fileRef = DEF78486291471D900A1F3A5 /* UNUserNotificationCenter+OneSignalNotifications.m */; };
DEF7848B291471DA00A1F3A5 /* UIApplicationDelegate+OneSignalNotifications.h in Headers */ = {isa = PBXBuildFile; fileRef = DEF78487291471DA00A1F3A5 /* UIApplicationDelegate+OneSignalNotifications.h */; };
Expand Down Expand Up @@ -1936,6 +1936,10 @@
DEBAAE4C2A42157B00BF2C1C /* UI */ = {
isa = PBXGroup;
children = (
DEF7847C29146B2700A1F3A5 /* OneSignalWebView.h */,
DEF7847B29146B2700A1F3A5 /* OneSignalWebView.m */,
DEF7848129146BD100A1F3A5 /* OneSignalWebViewManager.h */,
DEF7847F29146BBE00A1F3A5 /* OneSignalWebViewManager.m */,
DEBAAE512A42174A00BF2C1C /* OSInAppMessageView.h */,
DEBAAE532A42174A00BF2C1C /* OSInAppMessageView.m */,
DEBAAE522A42174A00BF2C1C /* OSInAppMessageViewController.h */,
Expand Down Expand Up @@ -2020,7 +2024,6 @@
children = (
DEF7842B2912DEBA00A1F3A5 /* OneSignalNotifications.h */,
DEF78485291471B200A1F3A5 /* Categories */,
DEF7847A29146B0B00A1F3A5 /* UI */,
DEF7844B2912E35700A1F3A5 /* NotificationSettings */,
DEF784482912E23A00A1F3A5 /* OSNotificationsManager.h */,
DEF784472912E23A00A1F3A5 /* OSNotificationsManager.m */,
Expand Down Expand Up @@ -2049,17 +2052,6 @@
path = NotificationSettings;
sourceTree = "<group>";
};
DEF7847A29146B0B00A1F3A5 /* UI */ = {
isa = PBXGroup;
children = (
DEF7847C29146B2700A1F3A5 /* OneSignalWebView.h */,
DEF7847B29146B2700A1F3A5 /* OneSignalWebView.m */,
DEF7848129146BD100A1F3A5 /* OneSignalWebViewManager.h */,
DEF7847F29146BBE00A1F3A5 /* OneSignalWebViewManager.m */,
);
path = UI;
sourceTree = "<group>";
};
DEF78485291471B200A1F3A5 /* Categories */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2241,8 +2233,10 @@
DEBAAE7E2A42176800BF2C1C /* OSInAppMessageDisplayStats.h in Headers */,
DEBAAE882A42176800BF2C1C /* OSInAppMessageClickEvent.h in Headers */,
DEBAAE7D2A42176800BF2C1C /* OSInAppMessagePage.h in Headers */,
DE70EB952A5CAD77003166D3 /* OneSignalWebViewManager.h in Headers */,
DEBAAE8B2A42176800BF2C1C /* OSInAppMessageClickResult.h in Headers */,
DEBAAE912A42176800BF2C1C /* OSInAppMessagePushPrompt.h in Headers */,
DE70EB942A5CAD70003166D3 /* OneSignalWebView.h in Headers */,
DEBAAE2B2A4211DA00BF2C1C /* OneSignalInAppMessages.h in Headers */,
DEBAAE8D2A42176800BF2C1C /* OSInAppMessageBridgeEvent.h in Headers */,
);
Expand All @@ -2254,13 +2248,11 @@
files = (
DEF7842C2912DEBA00A1F3A5 /* OneSignalNotifications.h in Headers */,
DEF784522912E3EB00A1F3A5 /* OneSignalNotificationSettings.h in Headers */,
DEF7848229146BD100A1F3A5 /* OneSignalWebViewManager.h in Headers */,
DEF7848C291471DA00A1F3A5 /* UNUserNotificationCenter+OneSignalNotifications.h in Headers */,
DEF7847229132AA700A1F3A5 /* OSNotification+OneSignal.h in Headers */,
DEF784582912E4BA00A1F3A5 /* OSPermission.h in Headers */,
DEF7848B291471DA00A1F3A5 /* UIApplicationDelegate+OneSignalNotifications.h in Headers */,
DEF7844A2912E23A00A1F3A5 /* OSNotificationsManager.h in Headers */,
DEF7847E29146B2700A1F3A5 /* OneSignalWebView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -3035,9 +3027,11 @@
DEBAAE812A42176800BF2C1C /* OSTrigger.m in Sources */,
DEBAAE832A42176800BF2C1C /* OSInAppMessageLocationPrompt.m in Sources */,
DEBAAE952A42177B00BF2C1C /* OSInAppMessagingRequests.m in Sources */,
DE70EB922A5CACF5003166D3 /* OneSignalWebViewManager.m in Sources */,
DEBAAE992A42179A00BF2C1C /* OneSignalInAppMessages.m in Sources */,
DEBAAE602A42175A00BF2C1C /* OSDynamicTriggerController.m in Sources */,
DEBAAE8A2A42176800BF2C1C /* OSInAppMessageInternal.m in Sources */,
DE70EB932A5CACF5003166D3 /* OneSignalWebView.m in Sources */,
DEBAAE872A42176800BF2C1C /* OSInAppMessageBridgeEvent.m in Sources */,
DEBAAE892A42176800BF2C1C /* OSInAppMessageClickEvent.m in Sources */,
DEBAAE842A42176800BF2C1C /* OSInAppMessageDisplayStats.m in Sources */,
Expand All @@ -3063,13 +3057,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DEF7848029146BBE00A1F3A5 /* OneSignalWebViewManager.m in Sources */,
DEF784592912E4BA00A1F3A5 /* OSPermission.m in Sources */,
DEF7847329132AA700A1F3A5 /* OSNotification+OneSignal.m in Sources */,
DEF784492912E23A00A1F3A5 /* OSNotificationsManager.m in Sources */,
DEF7848D291471DA00A1F3A5 /* UIApplicationDelegate+OneSignalNotifications.m in Sources */,
DEF784552912E3EB00A1F3A5 /* OneSignalNotificationSettings.m in Sources */,
DEF7847D29146B2700A1F3A5 /* OneSignalWebView.m in Sources */,
DEF7848A291471DA00A1F3A5 /* UNUserNotificationCenter+OneSignalNotifications.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@

// Notification
#define OSUD_LAST_MESSAGE_OPENED @"GT_LAST_MESSAGE_OPENED_" // * OSUD_MOST_RECENT_NOTIFICATION_OPENED
#define OSUD_NOTIFICATION_OPEN_LAUNCH_URL @"ONESIGNAL_INAPP_LAUNCH_URL" // * OSUD_NOTIFICATION_OPEN_LAUNCH_URL
#define OSUD_TEMP_CACHED_NOTIFICATION_MEDIA @"OSUD_TEMP_CACHED_NOTIFICATION_MEDIA" // OSUD_TEMP_CACHED_NOTIFICATION_MEDIA
// Remote Params
#define OSUD_LOCATION_ENABLED @"OSUD_LOCATION_ENABLED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
THE SOFTWARE.
*/

#import <OneSignalNotifications/OneSignalWebView.h>
#import "OneSignalWebView.h"

@interface OneSignalWebViewManager : NSObject
+ (OneSignalWebView *_Nonnull)webVC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,27 +735,14 @@ + (void)launchWebURL:(NSString*)openUrl {
}

+ (void)displayWebView:(NSURL*)url {
// Check if in-app or safari
__block BOOL inAppLaunch = [OneSignalUserDefaults.initStandard getSavedBoolForKey:OSUD_NOTIFICATION_OPEN_LAUNCH_URL defaultValue:false];

// If the URL contains itunes.apple.com, it's an app store link
// that should be opened using sharedApplication openURL
if ([[url absoluteString] rangeOfString:@"itunes.apple.com"].location != NSNotFound) {
inAppLaunch = NO;
}

__block let openUrlBlock = ^void(BOOL shouldOpen) {
if (!shouldOpen)
return;

[OneSignalCoreHelper dispatch_async_on_main_queue: ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (inAppLaunch && [OneSignalCoreHelper isWWWScheme:url]) {
[OneSignalWebViewManager displayWebView: url];
} else {
// Keep dispatch_async. Without this the url can take an extra 2 to 10 secounds to open.
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
// Keep dispatch_async. Without this the url can take an extra 2 to 10 secounds to open.
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
});
}];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@

#import <OneSignalNotifications/OSNotificationsManager.h>
#import <OneSignalNotifications/OSPermission.h>
#import <OneSignalNotifications/OneSignalWebView.h>
#import <OneSignalNotifications/OneSignalWebViewManager.h>
#import <OneSignalNotifications/OSNotification+OneSignal.h>
33 changes: 0 additions & 33 deletions iOS_SDK/OneSignalSDK/Source/OneSignal.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

/* Enable the default in-app launch urls*/
NSString* const kOSSettingsKeyInAppLaunchURL = @"kOSSettingsKeyInAppLaunchURL";

/* Omit no appId error logging, for use with wrapper SDKs. */
NSString* const kOSSettingsKeyInOmitNoAppIdLogging = @"kOSSettingsKeyInOmitNoAppIdLogging";

Expand Down Expand Up @@ -335,15 +332,6 @@ + (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;
appSettings = newSettings;
// This allows this method to have an effect after init is called
[self enableInAppLaunchURL:launchInApp];
}

+ (void)setProvidesNotificationSettingsView:(BOOL)providesView {
if (providesView && [OSDeviceUtils isIOSVersionGreaterThanOrEqual:@"12.0"]) {
[OSNotificationsManager setProvidesNotificationSettingsView: providesView];
Expand Down Expand Up @@ -441,21 +429,6 @@ + (void)startNewSessionInternal {
// [OSMessagingController.sharedInstance updateInAppMessagesFromCache]; // go to controller
}

+ (void)initInAppLaunchURLSettings:(NSDictionary*)settings {
// TODO: Make booleans on the class instead of as keys in a dictionary
let standardUserDefaults = OneSignalUserDefaults.initStandard;
// Check if disabled in-app launch url if passed a NO
if (settings[kOSSettingsKeyInAppLaunchURL] && [settings[kOSSettingsKeyInAppLaunchURL] isKindOfClass:[NSNumber class]])

[self enableInAppLaunchURL:[settings[kOSSettingsKeyInAppLaunchURL] boolValue]];

else if (![standardUserDefaults keyExists:OSUD_NOTIFICATION_OPEN_LAUNCH_URL]) {
// Only need to default to true if the app doesn't already have this setting saved in NSUserDefaults

[self enableInAppLaunchURL:true];
}
}

+ (void)startInAppMessages {
let oneSignalInAppMessages = NSClassFromString(@"OneSignalInAppMessages");
if (oneSignalInAppMessages != nil && [oneSignalInAppMessages respondsToSelector:@selector(start)]) {
Expand Down Expand Up @@ -536,8 +509,6 @@ + (void)init {

// Now really initializing the SDK!

[self initInAppLaunchURLSettings:appSettings];

// Invalid app ids reaching here will cause failure
if (![self isValidAppId:appId])
return;
Expand Down Expand Up @@ -690,10 +661,6 @@ + (void)downloadIOSParamsWithAppId:(NSString *)appId {
}];
}

+ (void)enableInAppLaunchURL:(BOOL)enable {
[OneSignalUserDefaults.initStandard saveBoolForKey:OSUD_NOTIFICATION_OPEN_LAUNCH_URL withValue:enable];
}

//TODO: consolidate in one place. Where???
+ (void)launchWebURL:(NSString*)openUrl {

Expand Down
1 change: 0 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ NS_SWIFT_NAME(login(externalId:token:));
#pragma mark Initialization
+ (void)setLaunchOptions:(nullable NSDictionary*)newLaunchOptions; // meant for use by wrappers
+ (void)initialize:(nonnull NSString*)newAppId withLaunchOptions:(nullable NSDictionary*)launchOptions;
+ (void)setLaunchURLsInApp:(BOOL)launchInApp;
+ (void)setProvidesNotificationSettingsView:(BOOL)providesView;

#pragma mark Live Activity
Expand Down
1 change: 0 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@interface OneSignalHelper : NSObject

// - Web
+ (OneSignalWebView*)webVC;
+ (void) displayWebView:(NSURL*)url;

// Threading
Expand Down
28 changes: 3 additions & 25 deletions iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ + (NSString*)mUserId;
@implementation OneSignalHelper


//Passed to the OnFocus to make sure dismissed when coming back into app
OneSignalWebView *webVC;
+ (OneSignalWebView*)webVC {
return webVC;
}

+ (NSString*)getAppName {
return [[[NSBundle mainBundle] infoDictionary] objectForKey:(id)kCFBundleNameKey];
}
Expand All @@ -73,31 +67,15 @@ + (OneSignal*)sharedInstance {
return singleInstance;
}

+ (void)displayWebView:(NSURL*)url {
// Check if in-app or safari
__block BOOL inAppLaunch = [OneSignalUserDefaults.initStandard getSavedBoolForKey:OSUD_NOTIFICATION_OPEN_LAUNCH_URL defaultValue:false];

// If the URL contains itunes.apple.com, it's an app store link
// that should be opened using sharedApplication openURL
if ([[url absoluteString] rangeOfString:@"itunes.apple.com"].location != NSNotFound) {
inAppLaunch = NO;
}

+ (void)displayWebView:(NSURL*)url {
__block let openUrlBlock = ^void(BOOL shouldOpen) {
if (!shouldOpen)
return;

[OneSignalHelper dispatch_async_on_main_queue: ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (inAppLaunch && [OneSignalCoreHelper isWWWScheme:url]) {
if (!webVC)
webVC = [[OneSignalWebView alloc] init];
webVC.url = url;
[webVC showInApp];
} else {
// Keep dispatch_async. Without this the url can take an extra 2 to 10 secounds to open.
[[UIApplication sharedApplication] openURL:url];
}
// Keep dispatch_async. Without this the url can take an extra 2 to 10 secounds to open.
[[UIApplication sharedApplication] openURL:url];
});
}];
};
Expand Down
16 changes: 0 additions & 16 deletions iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -3349,22 +3349,6 @@ - (void)testLaunchURL {
XCTAssertFalse(OneSignalOverrider.launchWebURLWasCalled);
}

- (void)testsetLaunchURLInAppAfterInit {
// 1. setLaunchURLsInApp to false
[OneSignal setLaunchURLsInApp:false];

// 2. Init OneSignal with app start
[UnitTestCommonMethods initOneSignal];
[UnitTestCommonMethods runBackgroundThreads];

XCTAssertFalse([OneSignalUserDefaults.initStandard getSavedBoolForKey:OSUD_NOTIFICATION_OPEN_LAUNCH_URL defaultValue:false]);

// 3. Change setLaunchURLsInApp to true
[OneSignal setLaunchURLsInApp:true];

XCTAssertTrue([OneSignalUserDefaults.initStandard getSavedBoolForKey:OSUD_NOTIFICATION_OPEN_LAUNCH_URL defaultValue:false]);
}

- (void)testTimezoneId {

let mockTimezone = [NSTimeZone timeZoneWithName:@"Europe/London"];
Expand Down

0 comments on commit d695d51

Please sign in to comment.