Skip to content
Open
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
10 changes: 3 additions & 7 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,9 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotificationWithPayload:notification.request.content.userInfo
completion:^(OSNotification *notif) {
if (notif) {
if (@available(iOS 14.0, *)) {
completionHandler(UNNotificationPresentationOptionBanner |
UNNotificationPresentationOptionList |
UNNotificationPresentationOptionSound);
} else {
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
}
completionHandler(UNNotificationPresentationOptionBanner |
UNNotificationPresentationOptionList |
UNNotificationPresentationOptionSound);
} else {
completionHandler(UNNotificationPresentationOptionNone);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class LiveActivityController: NSObject {
An example of starting a Live Activity whose attributes are "OneSignal SDK aware". The SDK will handle listening for update tokens on behalf of the app.
*/
static var counter1 = 0
@available(iOS 13.0, *)
@objc
static func createOneSignalAwareActivity(activityId: String) {
if #available(iOS 16.1, *) {
Expand All @@ -103,7 +102,6 @@ class LiveActivityController: NSObject {
/**
An example of starting a Live Activity using the DefaultLiveActivityAttributes. The SDK will handle listening for update tokens on behalf of the app.
*/
@available(iOS 13.0, *)
@objc
static func createDefaultActivity(activityId: String) {
if #available(iOS 16.1, *) {
Expand All @@ -118,7 +116,6 @@ class LiveActivityController: NSObject {
An example of starting a Live Activity whose attributes are **not** "OneSignal SDK aware". The app must handle listening for update tokens and notify the OneSignal SDK.
*/
static var counter2 = 0
@available(iOS 13.0, *)
@objc
static func createActivity(activityId: String) async {
if #available(iOS 16.1, *) {
Expand Down
22 changes: 9 additions & 13 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,15 @@ - (IBAction)sendUniqueOutcomeEvent:(id)sender {
- (IBAction)startAndEnterLiveActivity:(id)sender {
#if TARGET_OS_MACCATALYST
#else
if (@available(iOS 13.0, *)) {
NSString *activityId = [self.activityId text];
// Will not make a live activity if activityId is empty
if (activityId && activityId.length) {
// 1. Create a Default activity
// [LiveActivityController createDefaultActivityWithActivityId:activityId ];
// 2. Create non-OneSignal-aware activity
// [LiveActivityController createActivityWithActivityId:activityId completionHandler:^(void) {} ];
// 3. Create OneSignal-aware activity
[LiveActivityController createOneSignalAwareActivityWithActivityId:activityId];
}
} else {
NSLog(@"Must use iOS 13 or later for swift concurrency which is required for [LiveActivityController createActivityWithCompletionHandler...");
NSString *activityId = [self.activityId text];
// Will not make a live activity if activityId is empty
if (activityId && activityId.length) {
// 1. Create a Default activity
// [LiveActivityController createDefaultActivityWithActivityId:activityId ];
// 2. Create non-OneSignal-aware activity
// [LiveActivityController createActivityWithActivityId:activityId completionHandler:^(void) {} ];
// 3. Create OneSignal-aware activity
[LiveActivityController createOneSignalAwareActivityWithActivityId:activityId];
}
#endif
}
Expand Down
5 changes: 1 addition & 4 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSBundleUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
@implementation OSBundleUtils

+ (BOOL)isAppUsingUIScene {
if (@available(iOS 13.0, *)) {
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationSceneManifest"] != nil;
}
return NO;
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationSceneManifest"] != nil;
}

@end
20 changes: 6 additions & 14 deletions iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ public class OneSignalCoreMocks: NSObject {

@objc public static func backgroundApp() {
if OSBundleUtils.isAppUsingUIScene() {
if #available(iOS 13.0, *) {
NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil)
NotificationCenter.default.post(name: UIScene.didEnterBackgroundNotification, object: nil)
}
NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil)
NotificationCenter.default.post(name: UIScene.didEnterBackgroundNotification, object: nil)
} else {
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
NotificationCenter.default.post(name: UIApplication.didEnterBackgroundNotification, object: nil)
Expand All @@ -83,10 +81,8 @@ public class OneSignalCoreMocks: NSObject {

@objc public static func foregroundApp() {
if OSBundleUtils.isAppUsingUIScene() {
if #available(iOS 13.0, *) {
NotificationCenter.default.post(name: UIScene.willEnterForegroundNotification, object: nil)
NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil)
}
NotificationCenter.default.post(name: UIScene.willEnterForegroundNotification, object: nil)
NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil)
} else {
NotificationCenter.default.post(name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
Expand All @@ -95,19 +91,15 @@ public class OneSignalCoreMocks: NSObject {

@objc public static func resignActive() {
if OSBundleUtils.isAppUsingUIScene() {
if #available(iOS 13.0, *) {
NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil)
}
NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil)
} else {
NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil)
}
}

@objc public static func becomeActive() {
if OSBundleUtils.isAppUsingUIScene() {
if #available(iOS 13.0, *) {
NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil)
}
NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil)
} else {
NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,8 @@ @implementation DirectDownloadDelegate
@synthesize error, response, done;

-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
NSError * __autoreleasing fileHandleError;
NSError * __autoreleasing *fileHandleErrorPointer = &fileHandleError;
if (@available(iOS 13.0, *)) {
// We need to use NSInvocation for reflection because performSelector cannot take pointer parameters
SEL writeDataSelector = NSSelectorFromString(@"writeData:error:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSFileHandle instanceMethodSignatureForSelector:writeDataSelector]];
[invocation setTarget:outputHandle];
[invocation setSelector:writeDataSelector];
/*
From Apple's Documentation on NSInvocation:
Indices 0 and 1 indicate the hidden arguments self and _cmd, respectively;
you should set these values directly with the target and selector properties.
Use indices 2 and greater for the arguments normally passed in a message.
*/
[invocation setArgument:&data atIndex:2];
[invocation setArgument:&fileHandleErrorPointer atIndex:3];
[invocation invoke];
} else {
@try {
[outputHandle writeData:data];
} @catch (NSException *e) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey : @"Failed to write attachment data to filehandle",
};
fileHandleError = [NSError errorWithDomain:@"com.onesignal.download" code:0 userInfo:userInfo];
}
}
NSError *fileHandleError;
[outputHandle writeData:data error:&fileHandleError];

if (fileHandleError != nil) {
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"OneSignal Error encountered while downloading attachment: %@", fileHandleError]];
Expand Down Expand Up @@ -265,46 +240,16 @@ + (void)addAttachments:(OSNotification*)notification
+ (UNNotificationAction *)createActionForButton:(NSDictionary *)button {
NSString *buttonId = button[@"id"];
NSString *buttonText = button[@"text"];

if (@available(iOS 15.0, *)) {
// Using reflection for Xcode versions lower than 13
id icon; // UNNotificationActionIcon
let UNNotificationActionIconClass = NSClassFromString(@"UNNotificationActionIcon");
if (UNNotificationActionIconClass) {
if (button[@"systemIcon"]) {
icon = [UNNotificationActionIconClass performSelector:@selector(iconWithSystemImageName:)
withObject:button[@"systemIcon"]];
} else if (button[@"templateIcon"]) {
icon = [UNNotificationActionIconClass performSelector:@selector(iconWithTemplateImageName:)
withObject:button[@"templateIcon"]];
}
}

// We need to use NSInvocation because performSelector only allows up to 2 arguments
SEL actionSelector = NSSelectorFromString(@"actionWithIdentifier:title:options:icon:");
UNNotificationAction * __unsafe_unretained action;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UNNotificationAction methodSignatureForSelector:actionSelector]];
[invocation setTarget:[UNNotificationAction class]];
[invocation setSelector:actionSelector];
/*
From Apple's Documentation on NSInvocation:
Indices 0 and 1 indicate the hidden arguments self and _cmd, respectively;
you should set these values directly with the target and selector properties.
Use indices 2 and greater for the arguments normally passed in a message.
*/
NSUInteger actionOption = UNNotificationActionOptionForeground;
[invocation setArgument:&buttonId atIndex:2];
[invocation setArgument:&buttonText atIndex:3];
[invocation setArgument:&actionOption atIndex:4];
[invocation setArgument:&icon atIndex:5];
[invocation invoke];
[invocation getReturnValue:&action];
return action;
} else {
return [UNNotificationAction actionWithIdentifier:buttonId
title:buttonText
options:UNNotificationActionOptionForeground];
UNNotificationActionIcon *icon;
if (button[@"systemIcon"]) {
icon = [UNNotificationActionIcon iconWithSystemImageName:button[@"systemIcon"]];
} else if (button[@"templateIcon"]) {
icon = [UNNotificationActionIcon iconWithTemplateImageName:button[@"templateIcon"]];
}
return [UNNotificationAction actionWithIdentifier:buttonId
title:buttonText
options:UNNotificationActionOptionForeground
icon:icon];
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,13 +1173,7 @@ - (void)webViewContentFinishedLoading:(OSInAppMessageInternal *)message {
// Required to display if the app is using a Scene
// See https://github.com/OneSignal/OneSignal-iOS-SDK/issues/648
- (void)addKeySceneToWindow:(UIWindow*)window {
if (@available(iOS 13.0, *)) {
// The below lines can be replace with this single line once Xcode 10 support is dropped
// window.windowScene = UIApplication.sharedApplication.keyWindow.windowScene;
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
id windowScene = [keyWindow performSelector:@selector(windowScene)];
[window performSelector:@selector(setWindowScene:) withObject:windowScene];
}
window.windowScene = UIApplication.sharedApplication.keyWindow.windowScene;
}

- (void)dynamicTriggerCompleted:(NSString *)triggerId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ @implementation UIApplication (OneSignal)

+ (BOOL)applicationIsActive {
if ([OSBundleUtils isAppUsingUIScene] && [NSThread isMainThread]) {
if (@available(iOS 13.0, *)) {
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
id windowScene = [keyWindow performSelector:@selector(windowScene)];
id session = [windowScene performSelector:@selector(session)];
id scene = [session performSelector:@selector(scene)];
return [scene performSelector:@selector(activationState)] == 0;
}
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
return keyWindow.windowScene.activationState == UISceneActivationStateForegroundActive;
}
return [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,8 @@ - (void)getNotificationPermissionState:(void (^)(OSPermissionStateInternal *subs
status.answeredPrompt = settings.authorizationStatus != UNAuthorizationStatusNotDetermined && settings.authorizationStatus != provisionalStatus;
status.provisional = (settings.authorizationStatus == 3);
status.accepted = settings.authorizationStatus == UNAuthorizationStatusAuthorized && !status.provisional;
if (@available(iOS 14.0, *)) {
status.ephemeral = (settings.authorizationStatus == AUTH_STATUS_EPHEMERAL);
status.accepted = status.accepted || status.ephemeral;
} else {
status.ephemeral = false;
}
status.ephemeral = (settings.authorizationStatus == AUTH_STATUS_EPHEMERAL);
status.accepted = status.accepted || status.ephemeral;

status.notificationTypes = (settings.badgeSetting == UNNotificationSettingEnabled ? 1 : 0)
+ (settings.soundSetting == UNNotificationSettingEnabled ? 2 : 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,8 @@ + (void)registerLifecycleObserver {
}

+ (void)registerLifecycleObserverAsUIScene {
if (@available(iOS 13.0, *)) {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSNotificationManager registering for Scene Lifecycle notifications"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:@"UISceneWillEnterForegroundNotification" object:nil];
}
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSNotificationManager registering for Scene Lifecycle notifications"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:UISceneWillEnterForegroundNotification object:nil];
}

+ (void)registerLifecycleObserverAsUIApplication {
Expand Down
6 changes: 3 additions & 3 deletions iOS_SDK/OneSignalSDK/Source/OSRemoteLoggingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ final class OSRemoteLoggingController: NSObject, OSInternalLogSink {
private extension OSRemoteLoggingController {
func registerLifecycleObservers() {
if usesScenes() {
observe(Notification.Name("UISceneDidActivateNotification"), appState: "foreground")
observe(Notification.Name("UISceneWillDeactivateNotification"), appState: "unknown")
observe(Notification.Name("UISceneDidEnterBackgroundNotification"), appState: "background", flush: true)
observe(UIScene.didActivateNotification, appState: "foreground")
observe(UIScene.willDeactivateNotification, appState: "unknown")
observe(UIScene.didEnterBackgroundNotification, appState: "background", flush: true)
} else {
observe(UIApplication.didBecomeActiveNotification, appState: "foreground")
observe(UIApplication.willResignActiveNotification, appState: "unknown")
Expand Down
10 changes: 4 additions & 6 deletions iOS_SDK/OneSignalSDK/Source/OneSignalLifecycleObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ + (void)registerLifecycleObserver {
}

+ (void)registerLifecycleObserverAsUIScene {
if (@available(iOS 13.0, *)) {
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"registering for Scene Lifecycle notifications"];
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didEnterBackground) name:@"UISceneDidEnterBackgroundNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didBecomeActive) name:@"UISceneDidActivateNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(willResignActive) name:@"UISceneWillDeactivateNotification" object:nil];
}
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"registering for Scene Lifecycle notifications"];
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didEnterBackground) name:UISceneDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didBecomeActive) name:UISceneDidActivateNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(willResignActive) name:UISceneWillDeactivateNotification object:nil];
}

+ (void)registerLifecycleObserverAsUIApplication {
Expand Down
Loading