Skip to content

Commit 70862a8

Browse files
committed
fix(messaging): replace simulator check
1 parent 57d6c3e commit 70862a8

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

packages/firebase-core/platforms/ios/src/TNSFirebaseCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ typedef void(^LaunchCallback)();
44
@interface TNSFirebaseCore: NSObject
55
+(LaunchCallback) onAppFinishLaunchingCallback;
66
+(void) setOnAppFinishLaunchingCallback:(LaunchCallback)callback;
7+
+(BOOL) isSimulator;
78
@end

packages/firebase-core/platforms/ios/src/TNSFirebaseCore.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ + (LaunchCallback)onAppFinishLaunchingCallback {
99
+ (void)setOnAppFinishLaunchingCallback:(nullable LaunchCallback)callback {
1010
_onAppFinishLaunchingCallback = callback;
1111
}
12+
13+
+(BOOL) isSimulator {
14+
#if TARGET_IPHONE_SIMULATOR
15+
return true;
16+
#else
17+
return false;
18+
#endif
19+
}
1220
@end

packages/firebase-messaging/index.ios.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AuthorizationStatus, IMessaging, Permissions, Notification, RemoteMessa
44

55
export { AuthorizationStatus } from './common';
66

7-
declare const FIRApp, TNSFirebaseMessaging, FIRAuth, TNSUIApplicationDelegate;
7+
declare const FIRApp, TNSFirebaseMessaging, TNSFirebaseCore;
88

99
let _registerDeviceForRemoteMessages = {
1010
resolve: null,
@@ -60,8 +60,9 @@ export class Messaging implements IMessaging {
6060

6161
getToken(): Promise<string> {
6262
return new Promise((resolve, reject) => {
63-
if (UIDevice.currentDevice.name.toLocaleLowerCase().indexOf('simulator') !== -1 && !UIApplication.sharedApplication.registeredForRemoteNotifications) {
63+
if (!TNSFirebaseCore.isSimulator() && !UIApplication.sharedApplication.registeredForRemoteNotifications) {
6464
reject(new Error('You must be registered for remote messages before calling getToken, see messaging().registerDeviceForRemoteMessages()'));
65+
return;
6566
}
6667
this.native?.tokenWithCompletion((token, error) => {
6768
if (error) {
@@ -115,9 +116,8 @@ export class Messaging implements IMessaging {
115116
this.#onMessage = listener;
116117
if (listener) {
117118
TNSFirebaseMessaging.onMessageCallback = (dict) => {
118-
listener(deserialize(dict))
119-
}
120-
119+
listener(deserialize(dict));
120+
};
121121
} else {
122122
TNSFirebaseMessaging.onMessageCallback = null;
123123
}
@@ -127,8 +127,8 @@ export class Messaging implements IMessaging {
127127
this.#onToken = listener;
128128
if (listener) {
129129
TNSFirebaseMessaging.onTokenCallback = (value) => {
130-
listener(value)
131-
}
130+
listener(value);
131+
};
132132
} else {
133133
TNSFirebaseMessaging.onTokenCallback = null;
134134
}
@@ -138,26 +138,26 @@ export class Messaging implements IMessaging {
138138
this.#onNotificationTap = listener;
139139
if (listener) {
140140
TNSFirebaseMessaging.onNotificationTapCallback = (dict) => {
141-
listener(deserialize(dict))
142-
}
141+
listener(deserialize(dict));
142+
};
143143
} else {
144144
TNSFirebaseMessaging.onNotificationTapCallback = null;
145145
}
146146
}
147147

148148
registerDeviceForRemoteMessages(): Promise<void> {
149149
return new Promise((resolve, reject) => {
150-
if (UIDevice.currentDevice.name.toLocaleLowerCase().indexOf('simulator') > -1) {
150+
if (TNSFirebaseCore.isSimulator()) {
151151
ApplicationSettings.setBoolean(REMOTE_NOTIFICATIONS_REGISTRATION_STATUS, true);
152152
resolve();
153153
}
154-
TNSFirebaseMessaging.registerDeviceForRemoteMessagesCallback = (result, error)=>{
155-
if(error){
154+
TNSFirebaseMessaging.registerDeviceForRemoteMessagesCallback = (result, error) => {
155+
if (error) {
156156
reject(FirebaseError.fromNative(error));
157-
}else {
157+
} else {
158158
resolve(result);
159159
}
160-
}
160+
};
161161
if (UIApplication?.sharedApplication) {
162162
UIApplication?.sharedApplication?.registerForRemoteNotifications?.();
163163
} else {
@@ -288,4 +288,4 @@ export class Messaging implements IMessaging {
288288
get ios() {
289289
return this.native;
290290
}
291-
}
291+
}

0 commit comments

Comments
 (0)