Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 1 deletion iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
// This project exisits to make testing OneSignal SDK changes.

#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
#import <OneSignalFramework/OneSignalFramework.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener, OSUserStateObserver, OSLogListener>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate, OSNotificationPermissionObserver, OSInAppMessageLifecycleListener, OSPushSubscriptionObserver, OSNotificationLifecycleListener, OSInAppMessageClickListener, OSNotificationClickListener, OSUserStateObserver, OSLogListener>

@property (strong, nonatomic) UIWindow *window;

Expand Down
66 changes: 58 additions & 8 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// [FIRApp configure];
[UNUserNotificationCenter currentNotificationCenter].delegate = self;

NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
// Uncomment to test LogListener
Expand Down Expand Up @@ -197,17 +198,66 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
- (void)applicationWillTerminate:(UIApplication *)application {
}

// Remote
- (void)onLogEvent:(OneSignalLogEvent * _Nonnull)event {
NSLog(@"Dev App onLogEvent: %@", event.entry);
}

#pragma mark - Manual Integration APIs (for use when swizzling is disabled)

// Forward the APNs device token to OneSignal so it can register the device for push
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {

NSLog(@"application:didReceiveRemoteNotification:fetchCompletionHandler: %@", userInfo);
completionHandler(UIBackgroundFetchResultNoData);
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Dev App application:didRegisterForRemoteNotificationsWithDeviceToken %@", deviceToken);
[OneSignal.Notifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)onLogEvent:(OneSignalLogEvent * _Nonnull)event {
NSLog(@"Dev App onLogEvent: %@", event.entry);
// Forward APNs registration failures so OneSignal can log and retry appropriately
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Dev App application:didFailToRegisterForRemoteNotificationsWithError %@", error);
[OneSignal.Notifications didFailToRegisterForRemoteNotificationsWithError:error];
}

// Forward background / silent notifications for content-available processing
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"Dev App application:didReceiveRemoteNotification %@", userInfo);
[OneSignal.Notifications didReceiveRemoteNotification:userInfo
completionHandler:completionHandler];
}

// Forward foreground notifications so the SDK can invoke onWillDisplayNotification listeners
// and determine whether to show a banner. Completion returns nil for IAM previews.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSLog(@"Dev App userNotificationCenter:willPresentNotification %@", notification);
[OneSignal.Notifications
willPresentNotificationWithPayload:notification.request.content.userInfo
completion:^(OSNotification *notif) {
if (notif) {
if (@available(iOS 14.0, *)) {
completionHandler(UNNotificationPresentationOptionBanner |
UNNotificationPresentationOptionList |
UNNotificationPresentationOptionSound);
} else {
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionSound);
}
} else {
completionHandler(UNNotificationPresentationOptionNone);
}
}];
}

// Forward notification tap / action so the SDK can fire onClickNotification listeners
// and handle deep links and action buttons
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
NSLog(@"Dev App userNotificationCenter:didReceiveNotificationResponse %@", response);
[OneSignal.Notifications didReceiveNotificationResponse:response];
completionHandler();
}

@end
2 changes: 2 additions & 0 deletions iOS_SDK/OneSignalDevApp/OneSignalDevApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>OneSignal_disable_swizzling</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
#define GDPR_CONSENT_GRANTED @"GDPR_CONSENT_GRANTED"
#define ONESIGNAL_REQUIRE_PRIVACY_CONSENT @"OneSignal_require_privacy_consent"

// Swizzling
#define ONESIGNAL_DISABLE_SWIZZLING @"OneSignal_disable_swizzling"

// Badge handling
#define ONESIGNAL_DISABLE_BADGE_CLEARING @"OneSignal_disable_badge_clearing"
#define ONESIGNAL_APP_GROUP_NAME_KEY @"OneSignal_app_groups_key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ + (BOOL)swizzledClassInHeirarchy:(Class)delegateClass {
return false;
}

- (void)oneSignalDidRegisterForRemoteNotifications:(UIApplication*)app deviceToken:(NSData*)inDeviceToken {
- (void)oneSignalDidRegisterForRemoteNotifications:(UIApplication*)app deviceToken:(NSData*)deviceToken {
[OneSignalNotificationsAppDelegate traceCall:@"oneSignalDidRegisterForRemoteNotifications:deviceToken:"];

[OSNotificationsManager didRegisterForRemoteNotifications:app deviceToken:inDeviceToken];
[OSNotificationsManager processRegisteredDeviceToken:deviceToken];

SwizzlingForwarder *forwarder = [[SwizzlingForwarder alloc]
initWithTarget:self
Expand All @@ -125,14 +125,14 @@ - (void)oneSignalDidRegisterForRemoteNotifications:(UIApplication*)app deviceTok
application:didRegisterForRemoteNotificationsWithDeviceToken:
)
];
[forwarder invokeWithArgs:@[app, inDeviceToken]];
[forwarder invokeWithArgs:@[app, deviceToken]];
}

- (void)oneSignalDidFailRegisterForRemoteNotification:(UIApplication*)app error:(NSError*)err {
[OneSignalNotificationsAppDelegate traceCall:@"oneSignalDidFailRegisterForRemoteNotification:error:"];

if ([OneSignalConfigManager getAppId])
[OSNotificationsManager handleDidFailRegisterForRemoteNotification:err];
[OSNotificationsManager processFailedRemoteNotificationsRegistration:err];

SwizzlingForwarder *forwarder = [[SwizzlingForwarder alloc]
initWithTarget:self
Expand Down Expand Up @@ -180,7 +180,7 @@ - (void) oneSignalReceiveRemoteNotification:(UIApplication*)application UserInfo
else if (appState == UIApplicationStateActive && isVisibleNotification)
[OSNotificationsManager notificationReceived:userInfo wasOpened:NO];
else
startedBackgroundJob = [OSNotificationsManager receiveRemoteNotification:application UserInfo:userInfo completionHandler:forwarder.hasReceiver ? nil : completionHandler];
startedBackgroundJob = [OSNotificationsManager processReceivedRemoteNotification:userInfo completionHandler:forwarder.hasReceiver ? nil : completionHandler];
}

if (forwarder.hasReceiver) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ - (void)onesignalUserNotificationCenter:(UNUserNotificationCenter *)center

[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"onesignalUserNotificationCenter:willPresentNotification:withCompletionHandler: Fired! %@", notification.request.content.body]];

[OSNotificationsManager handleWillPresentNotificationInForegroundWithPayload:notification.request.content.userInfo withCompletion:^(OSNotification *responseNotif) {
[OSNotificationsManager processWillPresentNotificationWithPayload:notification.request.content.userInfo completion:^(OSNotification *responseNotif) {
UNNotificationPresentationOptions displayType = responseNotif != nil ? (UNNotificationPresentationOptions)7 : (UNNotificationPresentationOptions)0;
finishProcessingNotification(notification, center, displayType, completionHandler, self);
}];
Expand Down Expand Up @@ -377,19 +377,7 @@ + (BOOL)isDismissEvent:(UNNotificationResponse *)response {
}

+ (void)processiOS10Open:(UNNotificationResponse*)response {
if (![OneSignalConfigManager getAppId])
return;

if ([OneSignalNotificationsUNUserNotificationCenter isDismissEvent:response])
return;

if (![OneSignalCoreHelper isOneSignalPayload:response.notification.request.content.userInfo])
return;

let userInfo = [OneSignalCoreHelper formatApsPayloadIntoStandard:response.notification.request.content.userInfo
identifier:response.actionIdentifier];

[OSNotificationsManager notificationReceived:userInfo wasOpened:YES];
[OSNotificationsManager processNotificationResponse:response];
}

// Calls depercated pre-iOS 10 selector if one is set on the AppDelegate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ NS_SWIFT_NAME(onClick(event:));
+ (void)addPermissionObserver:(NSObject<OSNotificationPermissionObserver>*_Nonnull)observer NS_REFINED_FOR_SWIFT;
+ (void)removePermissionObserver:(NSObject<OSNotificationPermissionObserver>*_Nonnull)observer NS_REFINED_FOR_SWIFT;
+ (void)clearAll;
// Manual integration APIs (for use when swizzling is disabled via Info.plist)
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *_Nonnull)deviceToken
NS_SWIFT_NAME(didRegisterForRemoteNotifications(deviceToken:));
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *_Nonnull)error
NS_SWIFT_NAME(didFailToRegisterForRemoteNotifications(error:));
+ (BOOL)didReceiveRemoteNotification:(NSDictionary *_Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler
NS_SWIFT_NAME(didReceiveRemoteNotification(userInfo:completionHandler:));
+ (void)willPresentNotificationWithPayload:(NSDictionary *_Nonnull)payload completion:(OSNotificationDisplayResponse _Nonnull)completion
NS_SWIFT_NAME(willPresentNotification(payload:completion:));
+ (void)didReceiveNotificationResponse:(UNNotificationResponse *_Nonnull)response
NS_SWIFT_NAME(didReceiveNotificationResponse(_:));
+ (void)setBadgeCount:(NSInteger)badgeCount;
@end


Expand Down Expand Up @@ -116,10 +128,17 @@ NS_SWIFT_NAME(onClick(event:));
+ (void)handleNotificationActionWithUrl:(NSString* _Nullable)url actionID:(NSString* _Nonnull)actionID;
+ (void)clearBadgeCount:(BOOL)fromNotifOpened fromClearAll:(BOOL)fromClearAll;

+ (BOOL)receiveRemoteNotification:(UIApplication* _Nonnull)application UserInfo:(NSDictionary* _Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler;
+ (void)notificationReceived:(NSDictionary* _Nonnull)messageDict wasOpened:(BOOL)opened;
+ (void)handleWillPresentNotificationInForegroundWithPayload:(NSDictionary * _Nonnull)payload withCompletion:(OSNotificationDisplayResponse _Nonnull)completion;
+ (void)didRegisterForRemoteNotifications:(UIApplication *_Nonnull)app deviceToken:(NSData *_Nonnull)inDeviceToken;
+ (void)handleDidFailRegisterForRemoteNotification:(NSError*_Nonnull)err;
+ (void)checkProvisionalAuthorizationStatus;
+ (void)registerLifecycleObserver;
+ (BOOL)isSwizzlingDisabled;

// Internal entry points called by swizzled delegate paths
// These bypass the swizzling-active guard so the SDK doesn't block its own calls
+ (void)processRegisteredDeviceToken:(NSData *_Nonnull)deviceToken;
+ (void)processFailedRemoteNotificationsRegistration:(NSError *_Nonnull)error;
+ (BOOL)processReceivedRemoteNotification:(NSDictionary *_Nonnull)userInfo completionHandler:(void (^_Nonnull)(UIBackgroundFetchResult))completionHandler;
+ (void)processWillPresentNotificationWithPayload:(NSDictionary *_Nonnull)payload completion:(OSNotificationDisplayResponse _Nonnull)completion;
+ (void)processNotificationResponse:(UNNotificationResponse *_Nonnull)response;

@end
Loading
Loading