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
3 changes: 0 additions & 3 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSDeviceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@

@interface OSDeviceUtils : NSObject

+ (NSString *)getCurrentDeviceVersion;
+ (BOOL)isIOSVersionGreaterThanOrEqual:(NSString *)version;
+ (BOOL)isIOSVersionLessThan:(NSString *)version;
+ (NSString*)getDeviceVariant;

@end
Expand Down
12 changes: 0 additions & 12 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSDeviceUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ of this software and associated documentation files (the "Software"), to deal

@implementation OSDeviceUtils

+ (NSString *)getCurrentDeviceVersion {
return [[UIDevice currentDevice] systemVersion];
}

+ (BOOL)isIOSVersionGreaterThanOrEqual:(NSString *)version {
return [[self getCurrentDeviceVersion] compare:version options:NSNumericSearch] != NSOrderedAscending;
}

+ (BOOL)isIOSVersionLessThan:(NSString *)version {
return [[self getCurrentDeviceVersion] compare:version options:NSNumericSearch] == NSOrderedAscending;
}

+ (NSString*)getSystemInfoMachine {
// e.g. @"x86_64" or @"iPhone9,3"
struct utsname systemInfo;
Expand Down
4 changes: 1 addition & 3 deletions iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ - (void)parseAlertField:(NSObject*)alert {
_body = (NSString*)alert;
}

// Only used on iOS 9 and older.
// - Or if the OneSignal server hasn't received the iOS version update.
// May also be used if OneSignal server hasn't received the SDK version 2.4.0+ update event
// Parses minified payloads that can still arrive before the server receives current SDK and device metadata.
- (void)parseRemoteSlient:(NSDictionary*)payload {
[self parseAlertField:payload[@"m"]];
_badge = [payload[@"b"] intValue];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#define OSUD_PERMISSION_ACCEPTED_FROM @"ONESIGNAL_PERMISSION_ACCEPTED_LAST" // * OSUD_PERMISSION_ACCEPTED_FROM
#define OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_TO @"OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_TO" // OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_TO
#define OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_FROM @"OS_HAS_PROMPTED_FOR_NOTIFICATIONS_LAST" // * OSUD_WAS_PROMPTED_FOR_NOTIFICATIONS_FROM
#define OSUD_WAS_NOTIFICATION_PROMPT_ANSWERED_TO @"OS_NOTIFICATION_PROMPT_ANSWERED" // * OSUD_WAS_NOTIFICATION_PROMPT_ANSWERED_TO
#define OSUD_WAS_NOTIFICATION_PROMPT_ANSWERED_FROM @"OS_NOTIFICATION_PROMPT_ANSWERED_LAST" // * OSUD_WAS_NOTIFICATION_PROMPT_ANSWERED_FROM
#define OSUD_PROVISIONAL_PUSH_AUTHORIZATION_TO @"OSUD_PROVISIONAL_PUSH_AUTHORIZATION_TO" // OSUD_PROVISIONAL_PUSH_AUTHORIZATION_TO
#define OSUD_PROVISIONAL_PUSH_AUTHORIZATION_FROM @"ONESIGNAL_PROVISIONAL_AUTHORIZATION_LAST" // * OSUD_PROVISIONAL_PUSH_AUTHORIZATION_FROM
Expand Down Expand Up @@ -113,11 +112,6 @@
#define OSUD_UNSENT_ACTIVE_TIME @"GT_UNSENT_ACTIVE_TIME" // * OSUD_UNSENT_ACTIVE_TIME
#define OSUD_UNSENT_ACTIVE_TIME_ATTRIBUTED @"GT_UNSENT_ACTIVE_TIME_ATTRIBUTED" // * OSUD_UNSENT_ACTIVE_TIME_ATTRIBUTED

// Deprecated Selectors
#define DEPRECATED_SELECTORS @[ @"application:didReceiveLocalNotification:", \
@"application:handleActionWithIdentifier:forLocalNotification:completionHandler:", \
@"application:handleActionWithIdentifier:forLocalNotification:withResponseInfo:completionHandler:" ]

// To avoid undefined symbol compiler errors on older versions of Xcode,
// instead of using UNAuthorizationOptionProvisional directly, we will use
// it indirectly with these macros
Expand Down
6 changes: 2 additions & 4 deletions iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
@interface OneSignalExtension : NSObject
#pragma mark NotificationService Extension
#pragma clang diagnostic ignored "-Wnullability-completeness"
// iOS 10 only
// Process from Notification Service Extension.
// Used for iOS Media Attachemtns and Action Buttons.
+ (UNMutableNotificationContent*)didReceiveNotificationExtensionRequest:(UNNotificationRequest* _Nonnull)request withMutableNotificationContent:(UNMutableNotificationContent* _Nullable)replacementContent __deprecated_msg("Please use didReceiveNotificationExtensionRequest:withMutableNotificationContent:withContentHandler: instead.");
// Call from a UNNotificationServiceExtension on iOS 10 and later.
// Processes media attachments and action buttons.
+ (UNMutableNotificationContent*)didReceiveNotificationExtensionRequest:(UNNotificationRequest* _Nonnull)request withMutableNotificationContent:(UNMutableNotificationContent* _Nullable)replacementContent withContentHandler:(void (^)(UNNotificationContent *_Nonnull))contentHandler;
+ (UNMutableNotificationContent*)serviceExtensionTimeWillExpireRequest:(UNNotificationRequest* _Nonnull)request withMutableNotificationContent:(UNMutableNotificationContent* _Nullable)replacementContent;
@end
7 changes: 0 additions & 7 deletions iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ of this software and associated documentation files (the "Software"), to deal

@implementation OneSignalExtension

// Called from the app's Notification Service Extension
+ (UNMutableNotificationContent*)didReceiveNotificationExtensionRequest:(UNNotificationRequest*)request withMutableNotificationContent:(UNMutableNotificationContent*)replacementContent {
return [OneSignalNotificationServiceExtensionHandler
didReceiveNotificationExtensionRequest:request
withMutableNotificationContent:replacementContent];
}

// Called from the app's Notification Service Extension. Calls contentHandler() to display the notification
+ (UNMutableNotificationContent*)didReceiveNotificationExtensionRequest:(UNNotificationRequest*)request withMutableNotificationContent:(UNMutableNotificationContent*)replacementContent
withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ @implementation OSMessagingController
static dispatch_once_t once;
+ (OSMessagingController *)sharedInstance {
dispatch_once(&once, ^{
// Make sure only devices with iOS 10 or newer can use IAMs
if ([self doesDeviceSupportIAM]) {
sharedInstance = [OSMessagingController new];
} else {
Expand Down Expand Up @@ -209,9 +208,8 @@ + (BOOL)doesDeviceSupportIAM {
// We could support in the future after we reslove the display issues.
if ([@"Mac" isEqualToString:[OSDeviceUtils getDeviceVariant]])
return false;

// Only support iOS 10 and newer due to Safari 9 WebView issues
return [OSDeviceUtils isIOSVersionGreaterThanOrEqual:@"10.0"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isIOSVersion**** helpers in OSDeviceUtils have no more callers, let's remove them

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


return true;
}

- (instancetype)init {
Expand Down
39 changes: 18 additions & 21 deletions iOS_SDK/OneSignalSDK/OneSignalInAppMessages/UI/OSInAppMessageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,23 @@ - (void)resetWebViewToMaxBoundsAndResizeHeight:(void (^) (NSNumber *newHeight))
}

- (void)updateSafeAreaInsets {
if (@available(iOS 11, *)) {
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
CGFloat top = keyWindow.safeAreaInsets.top;
CGFloat bottom = keyWindow.safeAreaInsets.bottom;
CGFloat right = keyWindow.safeAreaInsets.right;
CGFloat left = keyWindow.safeAreaInsets.left;
NSString *safeAreaInsetsObjectString = [NSString stringWithFormat:OS_JS_SAFE_AREA_INSETS_OBJ,top, bottom, right, left];

NSString *setInsetsString = [NSString stringWithFormat:OS_SET_SAFE_AREA_INSETS_METHOD, safeAreaInsetsObjectString];
[self.webView evaluateJavaScript:setInsetsString completionHandler:^(NSDictionary *result, NSError * _Nullable error) {
if (error) {
NSString *errorMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Error: %@", OS_SET_SAFE_AREA_INSETS_METHOD, error];
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:errorMessage];
return;
}
NSString *successMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Success: %@", OS_SET_SAFE_AREA_INSETS_METHOD, result];
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:successMessage];
}];
}
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
CGFloat top = keyWindow.safeAreaInsets.top;
CGFloat bottom = keyWindow.safeAreaInsets.bottom;
CGFloat right = keyWindow.safeAreaInsets.right;
CGFloat left = keyWindow.safeAreaInsets.left;
NSString *safeAreaInsetsObjectString = [NSString stringWithFormat:OS_JS_SAFE_AREA_INSETS_OBJ,top, bottom, right, left];

NSString *setInsetsString = [NSString stringWithFormat:OS_SET_SAFE_AREA_INSETS_METHOD, safeAreaInsetsObjectString];
[self.webView evaluateJavaScript:setInsetsString completionHandler:^(NSDictionary *result, NSError * _Nullable error) {
if (error) {
NSString *errorMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Error: %@", OS_SET_SAFE_AREA_INSETS_METHOD, error];
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:errorMessage];
return;
}
NSString *successMessage = [NSString stringWithFormat:@"Javascript Method: %@ Evaluated with Success: %@", OS_SET_SAFE_AREA_INSETS_METHOD, result];
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:successMessage];
}];
}

- (NSNumber *)extractHeightFromMetaDataPayload:(NSDictionary *)result {
Expand All @@ -210,8 +208,7 @@ - (void)setupWebViewConstraints {
self.webView.layer.cornerRadius = 10.0f;
self.webView.layer.masksToBounds = true;

if (@available(iOS 11, *))
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

[self.webView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor].active = true;
[self.webView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,20 @@ - (void)parseContentData:(NSDictionary *)data {

- (NSString *)setContentInsetsInHTML:(NSString *)html {
NSMutableString *newHTML = [[NSMutableString alloc] initWithString:html];
if (@available(iOS 11, *)) {
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
if (!keyWindow) {
return newHTML;
}
CGFloat top = keyWindow.safeAreaInsets.top;
CGFloat bottom = keyWindow.safeAreaInsets.bottom;
CGFloat right = keyWindow.safeAreaInsets.right;
CGFloat left = keyWindow.safeAreaInsets.left;
NSString *safeAreaInsetsObjectString = [NSString stringWithFormat:OS_JS_SAFE_AREA_INSETS_OBJ,top, bottom, right, left];
NSString *insetsString = [NSString stringWithFormat:@"\n\n\
UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
if (!keyWindow) {
return newHTML;
}
CGFloat top = keyWindow.safeAreaInsets.top;
CGFloat bottom = keyWindow.safeAreaInsets.bottom;
CGFloat right = keyWindow.safeAreaInsets.right;
CGFloat left = keyWindow.safeAreaInsets.left;
NSString *safeAreaInsetsObjectString = [NSString stringWithFormat:OS_JS_SAFE_AREA_INSETS_OBJ,top, bottom, right, left];
NSString *insetsString = [NSString stringWithFormat:@"\n\n\
<script> \
setSafeAreaInsets(%@);\
</script>",safeAreaInsetsObjectString];
[newHTML appendString: insetsString];
}
[newHTML appendString: insetsString];
return newHTML;
}

Expand Down Expand Up @@ -367,17 +365,14 @@ - (void)addConstraintsForMessage {

// The safe area represents the anchors that are not obscurable by UI such
// as a notch or a rounded corner on newer iOS devices like iPhone X
// Note that Safe Area layout guides were only introduced in iOS 11
if (@available(iOS 11, *)) {
if (!self.isFullscreen) {
let safeArea = self.view.safeAreaLayoutGuide;
top = safeArea.topAnchor;
bottom = safeArea.bottomAnchor;
leading = safeArea.leadingAnchor;
trailing = safeArea.trailingAnchor;
center = safeArea.centerXAnchor;
height = safeArea.heightAnchor;
}
if (!self.isFullscreen) {
let safeArea = self.view.safeAreaLayoutGuide;
top = safeArea.topAnchor;
bottom = safeArea.bottomAnchor;
leading = safeArea.leadingAnchor;
trailing = safeArea.trailingAnchor;
center = safeArea.centerXAnchor;
height = safeArea.heightAnchor;
}

CGRect mainBounds = [OneSignalCoreHelper getScreenBounds];
Expand Down Expand Up @@ -419,11 +414,9 @@ - (void)addConstraintsForMessage {
double bannerHeight = self.message.height.doubleValue + (2.0f * marginSpacing);
double bannerMessageY = mainBounds.size.height - bannerHeight;
switch (self.message.position) {
case OSInAppMessageDisplayPositionTop:
if (@available(iOS 11, *)) {
UIEdgeInsets safeAreaInsets = self.view.window.safeAreaInsets;
bannerHeight += safeAreaInsets.top + safeAreaInsets.bottom;
}
case OSInAppMessageDisplayPositionTop: {
UIEdgeInsets safeAreaInsets = self.view.window.safeAreaInsets;
bannerHeight += safeAreaInsets.top + safeAreaInsets.bottom;
double statusBarHeight = UIApplication.sharedApplication.statusBarFrame.size.height;
bannerHeight += statusBarHeight;
self.view.window.frame = CGRectMake(0, 0, bannerWidth, bannerHeight);
Expand All @@ -434,12 +427,11 @@ - (void)addConstraintsForMessage {
self.panVerticalConstraint = [self.messageView.topAnchor constraintEqualToAnchor:top
constant:(self.useHeightMargin ? marginSpacing : 0)];
break;
case OSInAppMessageDisplayPositionBottom:
if (@available(iOS 11, *)) {
UIEdgeInsets safeAreaInsets = self.view.window.safeAreaInsets;
bannerHeight += safeAreaInsets.top + safeAreaInsets.bottom;
bannerMessageY = mainBounds.size.height - bannerHeight;
}
}
case OSInAppMessageDisplayPositionBottom: {
UIEdgeInsets safeAreaInsets = self.view.window.safeAreaInsets;
bannerHeight += safeAreaInsets.top + safeAreaInsets.bottom;
bannerMessageY = mainBounds.size.height - bannerHeight;
self.view.window.frame = CGRectMake(0, bannerMessageY, bannerWidth, bannerHeight);

self.initialYConstraint = [self.messageView.topAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:8.0f];
Expand All @@ -448,15 +440,14 @@ - (void)addConstraintsForMessage {
self.panVerticalConstraint = [self.messageView.bottomAnchor constraintEqualToAnchor:bottom
constant:(self.useHeightMargin ? -marginSpacing : 0)];
break;
}
case OSInAppMessageDisplayPositionFullScreen:
case OSInAppMessageDisplayPositionCenterModal:
self.view.window.frame = mainBounds;
NSLayoutAnchor *centerYanchor = self.view.centerYAnchor;
if (@available(iOS 11, *)) {
if (!self.isFullscreen) {
let safeArea = self.view.safeAreaLayoutGuide;
centerYanchor = safeArea.centerYAnchor;
}
if (!self.isFullscreen) {
let safeArea = self.view.safeAreaLayoutGuide;
centerYanchor = safeArea.centerYAnchor;
}

self.initialYConstraint = [self.messageView.centerYAnchor constraintEqualToAnchor:centerYanchor constant:0.0f];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ + (void)internalGetLocation:(bool)prompt fallbackToSettings:(BOOL)fallback {
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[locationManager performSelector:NSSelectorFromString(@"requestAlwaysAuthorization")];
#pragma clang diagnostic pop
if ([OSDeviceUtils isIOSVersionGreaterThanOrEqual:@"9.0"])
[locationManager setValue:@YES forKey:@"allowsBackgroundLocationUpdates"];
[locationManager setValue:@YES forKey:@"allowsBackgroundLocationUpdates"];
}

else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
#import <objc/runtime.h>
#import "OSMacros.h"

// This class hooks into the UIApplicationDelegate selectors to receive iOS 9 and older events.
// - UNUserNotificationCenter is used for iOS 10
// - Orignal implementations are called so other plugins and the developers AppDelegate is still called.
// Hooks notification registration and background delivery selectors.
// Original implementations are called so other plugins and the app delegate still receive them.

@implementation OneSignalNotificationsAppDelegate

Expand Down Expand Up @@ -69,9 +68,8 @@ - (void) setOneSignalDelegate:(id<UIApplicationDelegate>)delegate {

Class newClass = [OneSignalNotificationsAppDelegate class];

// Need to keep this one for iOS 10 for content-available notifiations when the app is not in focus
// iOS 10 doesn't fire a selector on UNUserNotificationCenter in this cases most likely becuase
// UNNotificationServiceExtension (mutable-content) and UNNotificationContentExtension (with category) replaced it.
// Background content-available notifications are delivered through UIApplicationDelegate,
// not UNUserNotificationCenterDelegate.
injectSelector(
delegateClass,
@selector(application:didReceiveRemoteNotification:fetchCompletionHandler:),
Expand Down Expand Up @@ -149,9 +147,7 @@ - (void)oneSignalDidFailRegisterForRemoteNotification:(UIApplication*)app error:

// Fires when a notication is opened or recieved while the app is in focus.
// - Also fires when the app is in the background and a notificaiton with content-available=1 is received.
// NOTE: completionHandler must only be called once!
// iOS 10 - This crashes the app if it is called twice! Crash will happen when the app is resumed.
// iOS 9 - Does not have this issue.
// NOTE: completionHandler must only be called once.
- (void) oneSignalReceiveRemoteNotification:(UIApplication*)application UserInfo:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult)) completionHandler {
[OneSignalNotificationsAppDelegate traceCall:@"oneSignalReceiveRemoteNotification:UserInfo:fetchCompletionHandler:"];
SwizzlingForwarder *forwarder = [[SwizzlingForwarder alloc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ typedef void(^OSUserResponseBlock)(BOOL accepted);
- (void)getNotificationPermissionState:(void (^)(OSPermissionStateInternal *subscriptionState))completionHandler;
- (void)promptForNotifications:(OSUserResponseBlock)block;
- (void)registerForProvisionalAuthorization:(OSUserResponseBlock)block;
// Only used for iOS 9
- (void)onNotificationPromptResponse:(int)notificationTypes;
+(dispatch_queue_t)getQueue;
@end

Expand Down
Loading
Loading