Skip to content

Commit a407064

Browse files
committed
Merge pull request #1 from ianlin/wakeup-by-push-constant
Wakeup by push constant
2 parents fc348f6 + 3048679 commit a407064

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ class MyComponent extends React.Component {
113113
// register your VoIP client, show local notification, etc.
114114
// e.g.
115115
this.doRegister();
116+
117+
/* there is a boolean constant exported by this module called
118+
*
119+
* wakeupByPush
120+
*
121+
* you can use this constant to distinguish the app is launched
122+
* by VoIP push notification or not
123+
*
124+
* e.g.
125+
*/
126+
if (VoipPushNotification.wakeupByPush) {
127+
// do something...
128+
129+
// remember to set this static variable to false
130+
// since the constant are exported only at initialization time
131+
// and it will keep the same in the whole app
132+
VoipPushNotification.wakeupByPush = false;
133+
}
116134

117135
/**
118136
* Local Notification Payload

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)