Skip to content

Commit 0b72635

Browse files
committed
export a constant indicates the app is launched by voip push notification
1 parent fc348f6 commit 0b72635

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ var DEVICE_LOCAL_NOTIF_EVENT = 'voipLocalNotificationReceived';
1616

1717
export default class RNVoipPushNotification {
1818

19+
static wakeupByPush = (RNVoipPushNotificationManager.wakeupByPush === 'true');
20+
1921
/**
2022
* Schedules the localNotification for immediate presentation.
2123
*

ios/RNVoipPushNotification/RNVoipPushNotificationManager.m

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,28 @@
1414
#import "RCTEventDispatcher.h"
1515
#import "RCTUtils.h"
1616

17-
NSString *const RNVoipRemoteNotificationsRegistered = @"VoipRemoteNotificationsRegistered";
18-
NSString *const RNVoipLocalNotificationReceived = @"VoipLocalNotificationReceived";
19-
NSString *const RNVoipRemoteNotificationReceived = @"VoipRemoteNotificationReceived";
17+
NSString *const RNVoipRemoteNotificationsRegistered = @"voipRemoteNotificationsRegistered";
18+
NSString *const RNVoipLocalNotificationReceived = @"voipLocalNotificationReceived";
19+
NSString *const RNVoipRemoteNotificationReceived = @"voipRemoteNotificationReceived";
20+
21+
static NSString *RCTCurrentAppBackgroundState()
22+
{
23+
static NSDictionary *states;
24+
static dispatch_once_t onceToken;
25+
dispatch_once(&onceToken, ^{
26+
states = @{
27+
@(UIApplicationStateActive): @"active",
28+
@(UIApplicationStateBackground): @"background",
29+
@(UIApplicationStateInactive): @"inactive"
30+
};
31+
});
32+
33+
if (RCTRunningInAppExtension()) {
34+
return @"extension";
35+
}
36+
37+
return states[@(RCTSharedApplication().applicationState)] ? : @"unknown";
38+
}
2039

2140
@implementation RCTConvert (UILocalNotification)
2241

@@ -64,6 +83,13 @@ - (void)setBridge:(RCTBridge *)bridge
6483
object:nil];
6584
}
6685

86+
- (NSDictionary<NSString *, id> *)constantsToExport
87+
{
88+
NSString *currentState = RCTCurrentAppBackgroundState();
89+
NSLog(@"[RNVoipPushNotificationManager] constantsToExport currentState = %@", currentState);
90+
return @{@"wakeupByPush": (currentState == @"background") ? @"true" : @"false"};
91+
}
92+
6793
- (void)registerUserNotification:(NSDictionary *)permissions
6894
{
6995
UIUserNotificationType types = UIUserNotificationTypeNone;

0 commit comments

Comments
 (0)