Skip to content

Commit 1a48374

Browse files
committed
Sending updated notification types and push token
1 parent 5ac1227 commit 1a48374

File tree

6 files changed

+32
-35
lines changed

6 files changed

+32
-35
lines changed

iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UIApplicationDelegate+OneSignalNotifications.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ - (void)oneSignalDidRegisterForRemoteNotifications:(UIApplication*)app deviceTok
113113
- (void)oneSignalDidFailRegisterForRemoteNotification:(UIApplication*)app error:(NSError*)err {
114114
[OneSignalNotificationsAppDelegate traceCall:@"oneSignalDidFailRegisterForRemoteNotification:error:"];
115115

116-
if ([OSNotificationsManager getAppId])
116+
if ([OneSignalConfigManager getAppId])
117117
[OSNotificationsManager handleDidFailRegisterForRemoteNotification:err];
118118

119119
SwizzlingForwarder *forwarder = [[SwizzlingForwarder alloc]
@@ -147,7 +147,7 @@ - (void) oneSignalReceiveRemoteNotification:(UIApplication*)application UserInfo
147147

148148
BOOL startedBackgroundJob = false;
149149

150-
if ([OSNotificationsManager getAppId]) {
150+
if ([OneSignalConfigManager getAppId]) {
151151
let appState = [UIApplication sharedApplication].applicationState;
152152
let isVisibleNotification = userInfo[@"aps"][@"alert"] != nil;
153153

iOS_SDK/OneSignalSDK/OneSignalNotifications/Categories/UNUserNotificationCenter+OneSignalNotifications.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void finishProcessingNotification(UNNotification *notification,
277277

278278
[OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"Notification display type: %lu", (unsigned long)displayType]];
279279

280-
if ([OSNotificationsManager getAppId])
280+
if ([OneSignalConfigManager getAppId])
281281
[OSNotificationsManager notificationReceived:notification.request.content.userInfo wasOpened:NO];
282282

283283

@@ -353,7 +353,7 @@ + (BOOL)isDismissEvent:(UNNotificationResponse *)response {
353353
}
354354

355355
+ (void)processiOS10Open:(UNNotificationResponse*)response {
356-
if (![OSNotificationsManager getAppId])
356+
if (![OneSignalConfigManager getAppId])
357357
return;
358358

359359
if ([OneSignalNotificationsUNUserNotificationCenter isDismissEvent:response])

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ typedef void (^OSNotificationOpenedBlock)(OSNotificationOpenedResult * _Nonnull
6767
@property (class, weak, nonatomic, nullable) id<OneSignalNotificationsDelegate> delegate;
6868

6969
+ (Class<OSNotifications> _Nonnull)Notifications;
70-
70+
+ (void)start;
7171
+ (void)setColdStartFromTapOnNotification:(BOOL)coldStartFromTapOnNotification;
7272
+ (BOOL)getColdStartFromTapOnNotification;
73-
+ (void)setAppId:(NSString *_Nullable)appId;
74-
+ (NSString *_Nullable)getAppId;
7573

7674
@property (class, readonly) OSPermissionStateInternal* _Nonnull currentPermissionState;
7775
@property (class) OSPermissionStateInternal* _Nonnull lastPermissionState;

iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ of this software and associated documentation files (the "Software"), to deal
3232
#import "OSNotification+OneSignal.h"
3333
#import <OneSignalExtension/OneSignalAttachmentHandler.h>
3434
#import "OneSignalWebViewManager.h"
35+
#import "UNUserNotificationCenter+OneSignalNotifications.h"
36+
#import "UIApplicationDelegate+OneSignalNotifications.h"
3537

3638
@implementation OSNotificationOpenedResult
3739
@synthesize notification = _notification, action = _action;
@@ -183,6 +185,25 @@ + (void)setPushSubscriptionId:(NSString *)pushSubscriptionId {
183185
_pushSubscriptionId = pushSubscriptionId;
184186
}
185187

188+
+ (void)start {
189+
// Swizzle - UIApplication delegate
190+
//TODO: do the equivalent in the notificaitons module
191+
injectSelector(
192+
[UIApplication class],
193+
@selector(setDelegate:),
194+
[OneSignalNotificationsAppDelegate class],
195+
@selector(setOneSignalDelegate:)
196+
);
197+
//TODO: This swizzling is done from notifications module
198+
injectSelector(
199+
[UIApplication class],
200+
@selector(setApplicationIconBadgeNumber:),
201+
[OneSignalNotificationsAppDelegate class],
202+
@selector(onesignalSetApplicationIconBadgeNumber:)
203+
);
204+
[OneSignalNotificationsUNUserNotificationCenter setup];
205+
}
206+
186207
+ (void)resetLocals {
187208
_lastMessageReceived = nil;
188209
_lastMessageIdFromAction = nil;
@@ -354,10 +375,8 @@ + (void)didRegisterForRemoteNotifications:(UIApplication *)app
354375

355376
self.waitingForApnsResponse = false;
356377

357-
if (!_appId)
358-
return;
359-
360378
_pushToken = parsedDeviceToken;
379+
361380
[self sendPushTokenToDelegate];
362381
}
363382

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import OneSignalCore
2929
import OneSignalNotifications
30+
import OneSignalOSCore
3031

3132
/**
3233
Involved in the login process and responsible for Identify User and Create User.
@@ -774,7 +775,9 @@ class OSRequestUpdateSubscription: OneSignalRequest, OSUserRequest {
774775
// Rename "address" key as "token", if it exists
775776
var subscriptionParams = subscriptionObject
776777
subscriptionParams.removeValue(forKey: "address")
778+
subscriptionParams.removeValue(forKey: "notificationTypes")
777779
subscriptionParams["token"] = subscriptionObject["address"]
780+
subscriptionParams["notification_types"] = subscriptionObject["notificationTypes"]
778781

779782
self.parameters = ["subscription": subscriptionParams]
780783
self.method = PATCH

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -842,23 +842,8 @@ + (void)load {
842842
return;
843843
}
844844

845-
// Swizzle - UIApplication delegate
846-
//TODO: do the equivalent in the notificaitons module
847-
injectSelector(
848-
[UIApplication class],
849-
@selector(setDelegate:),
850-
[OneSignalAppDelegate class],
851-
@selector(setOneSignalDelegate:)
852-
);
853-
//TODO: This swizzling is done from notifications module
854-
injectSelector(
855-
[UIApplication class],
856-
@selector(setApplicationIconBadgeNumber:),
857-
[OneSignalAppDelegate class],
858-
@selector(onesignalSetApplicationIconBadgeNumber:)
859-
);
860-
//TODO: Do this in the notifications module
861-
[self setupUNUserNotificationCenterDelegate];
845+
[OSNotificationsManager start];
846+
862847
[[OSMigrationController new] migrate];
863848
sessionLaunchTime = [NSDate date];
864849

@@ -875,14 +860,6 @@ - (void)onesignalSetApplicationIconBadgeNumber:(NSInteger)badge {
875860
[self onesignalSetApplicationIconBadgeNumber:badge];
876861
}
877862

878-
+(void)setupUNUserNotificationCenterDelegate {
879-
// Swizzle - UNUserNotificationCenter delegate - iOS 10+
880-
if (!NSClassFromString(@"UNUserNotificationCenter"))
881-
return;
882-
883-
//[OneSignalUNUserNotificationCenter setup]; TODO: do this is notifications
884-
}
885-
886863
+(BOOL) shouldDisableBasedOnProcessArguments {
887864
if ([NSProcessInfo.processInfo.arguments containsObject:@"DISABLE_ONESIGNAL_SWIZZLING"]) {
888865
return YES;

0 commit comments

Comments
 (0)