Skip to content

Commit d926d3c

Browse files
committed
refactor(ios): remove legacy Xcode project and update imports
1 parent e79c0f5 commit d926d3c

File tree

4 files changed

+18
-80
lines changed

4 files changed

+18
-80
lines changed

examples/demo/bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/RCTOneSignal/RCTOneSignal.mm

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
1-
#if __has_include(<React/RCTConvert.h>)
2-
#import <React/RCTBridge.h>
3-
#import <React/RCTConvert.h>
4-
#import <React/RCTEventDispatcher.h>
5-
#import <React/RCTUtils.h>
6-
#else
7-
#import "RCTBridge.h"
8-
#import "RCTConvert.h"
9-
#import "RCTEventDispatcher.h"
10-
#import "RCTUtils.h"
11-
#endif
12-
131
#import "RCTOneSignal.h"
142
#import "RCTOneSignalEventEmitter.h"
153

16-
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
17-
18-
#define UIUserNotificationTypeAlert UIRemoteNotificationTypeAlert
19-
#define UIUserNotificationTypeBadge UIRemoteNotificationTypeBadge
20-
#define UIUserNotificationTypeSound UIRemoteNotificationTypeSound
21-
#define UIUserNotificationTypeNone UIRemoteNotificationTypeNone
22-
#define UIUserNotificationType UIRemoteNotificationType
23-
24-
#endif
25-
264
@interface RCTOneSignal ()
275
@end
286

297
@implementation RCTOneSignal {
308
BOOL didInitialize;
319
}
3210

33-
OSNotificationClickResult *coldStartOSNotificationClickResult;
34-
3511
+ (RCTOneSignal *)sharedInstance {
3612
static dispatch_once_t token = 0;
3713
static id _sharedInstance = nil;
@@ -54,29 +30,6 @@ - (void)initOneSignal:(NSDictionary *)launchOptions {
5430
didInitialize = true;
5531
}
5632

57-
- (void)handleRemoteNotificationOpened:(NSString *)result {
58-
NSDictionary *json = [self jsonObjectWithString:result];
59-
60-
if (json) {
61-
[self sendEvent:OSEventString(NotificationClicked) withBody:json];
62-
}
63-
}
64-
65-
- (NSDictionary *)jsonObjectWithString:(NSString *)jsonString {
66-
NSError *jsonError;
67-
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
68-
NSDictionary *json =
69-
[NSJSONSerialization JSONObjectWithData:data
70-
options:NSJSONReadingMutableContainers
71-
error:&jsonError];
72-
73-
if (jsonError) {
74-
return nil;
75-
}
76-
77-
return json;
78-
}
79-
8033
- (void)sendEvent:(NSString *)eventName withBody:(NSDictionary *)body {
8134
[RCTOneSignalEventEmitter sendEventWithName:eventName withBody:body];
8235
}
@@ -176,8 +129,4 @@ - (void)onDidDismissInAppMessage:
176129
withBody:[event jsonRepresentation]];
177130
}
178131

179-
- (void)dealloc {
180-
[[NSNotificationCenter defaultCenter] removeObserver:self];
181-
}
182-
183132
@end

ios/RCTOneSignal/RCTOneSignalEventEmitter.mm

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#pragma GCC diagnostic push
77
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
88

9+
@interface RCTOneSignalEventEmitter ()
10+
- (void)emitEventWithName:(NSString *)name body:(NSDictionary *)body;
11+
@end
12+
913
@implementation RCTOneSignalEventEmitter {
1014
BOOL _hasSetSubscriptionObserver;
1115
BOOL _hasSetPermissionObserver;
@@ -31,12 +35,6 @@ - (instancetype)init {
3135
_preventDefaultCache = [NSMutableDictionary new];
3236
_notificationWillDisplayCache = [NSMutableDictionary new];
3337

34-
for (NSString *eventName in OSNotificationEventTypesArray)
35-
[[NSNotificationCenter defaultCenter] addObserver:self
36-
selector:@selector(emitEvent:)
37-
name:eventName
38-
object:nil];
39-
4038
// Clean up previous instance if it exists (handles reload scenario)
4139
if (_currentInstance != nil && _currentInstance != self) {
4240
[_currentInstance removeHandlers];
@@ -51,7 +49,11 @@ - (instancetype)init {
5149
- (void)invalidate {
5250
[self removeHandlers];
5351
[self removeObservers];
54-
[[NSNotificationCenter defaultCenter] removeObserver:self];
52+
[_preventDefaultCache removeAllObjects];
53+
[_notificationWillDisplayCache removeAllObjects];
54+
if (_currentInstance == self) {
55+
_currentInstance = nil;
56+
}
5557
}
5658

5759
- (NSArray<NSString *> *)processNSError:(NSError *)error {
@@ -66,14 +68,11 @@ - (void)invalidate {
6668

6769
#pragma mark Send Event Methods
6870

69-
- (void)emitEvent:(NSNotification *)notification {
71+
- (void)emitEventWithName:(NSString *)name body:(NSDictionary *)body {
7072
if (!_eventEmitterCallback) {
7173
return;
7274
}
7375

74-
NSString *name = notification.name;
75-
NSDictionary *body = notification.userInfo;
76-
7776
if ([name isEqualToString:OSEventString(PermissionChanged)]) {
7877
[self emitOnPermissionChanged:body];
7978
} else if ([name isEqualToString:OSEventString(SubscriptionChanged)]) {
@@ -99,9 +98,7 @@ - (void)emitEvent:(NSNotification *)notification {
9998
}
10099

101100
+ (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
102-
[[NSNotificationCenter defaultCenter] postNotificationName:name
103-
object:nil
104-
userInfo:body];
101+
[_currentInstance emitEventWithName:name body:body];
105102
}
106103

107104
#pragma mark Exported Methods
@@ -341,7 +338,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
341338
}
342339
}
343340

344-
RCT_EXPORT_METHOD(removePermissionObserver) {
341+
- (void)removePermissionObserver {
345342
if (_hasSetPermissionObserver) {
346343
[OneSignal.Notifications
347344
removePermissionObserver:[RCTOneSignal sharedInstance]];
@@ -370,22 +367,14 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
370367

371368
RCT_EXPORT_METHOD(onWillDisplayNotification : (OSNotificationWillDisplayEvent *)
372369
event) {
373-
__weak RCTOneSignalEventEmitter *weakSelf = self;
374-
RCTOneSignalEventEmitter *strongSelf = weakSelf;
375-
if (!strongSelf)
376-
return;
377-
378-
strongSelf->_notificationWillDisplayCache[event.notification.notificationId] =
379-
event;
370+
_notificationWillDisplayCache[event.notification.notificationId] = event;
380371
[event preventDefault];
381372
[RCTOneSignalEventEmitter
382373
sendEventWithName:@"OneSignal-notificationWillDisplayInForeground"
383374
withBody:[event.notification jsonRepresentation]];
384375
}
385376

386377
RCT_EXPORT_METHOD(preventDefault : (NSString *)notificationId) {
387-
__weak RCTOneSignalEventEmitter *weakSelf = self;
388-
RCTOneSignalEventEmitter *strongSelf = weakSelf;
389378
OSNotificationWillDisplayEvent *event =
390379
_notificationWillDisplayCache[notificationId];
391380
if (!event) {
@@ -398,7 +387,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
398387
notificationId]];
399388
return;
400389
}
401-
strongSelf->_preventDefaultCache[event.notification.notificationId] = event;
390+
_preventDefaultCache[event.notification.notificationId] = event;
402391
[event preventDefault];
403392
}
404393

@@ -442,7 +431,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
442431
}
443432
}
444433

445-
RCT_EXPORT_METHOD(removePushSubscriptionObserver) {
434+
- (void)removePushSubscriptionObserver {
446435
if (_hasSetSubscriptionObserver) {
447436
[OneSignal.User.pushSubscription
448437
removeObserver:[RCTOneSignal sharedInstance]];
@@ -625,3 +614,5 @@ - (void)removeUserStateObserver {
625614
}
626615

627616
@end
617+
618+
#pragma GCC diagnostic pop

ios/RCTOneSignal/UIApplication+RCTOnesignal.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
@interface RCTOneSignal
55
+ (RCTOneSignal *)sharedInstance;
6-
- (void)initialize:(nonnull NSString *)newAppId
7-
withLaunchOptions:(nullable NSDictionary *)launchOptions;
86
- (void)initOneSignal:(NSDictionary *)launchOptions;
97
@end
108

0 commit comments

Comments
 (0)