Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ class MyComponent extends React.Component {
// register your VoIP client, show local notification, etc.
// e.g.
this.doRegister();

/* there is a boolean constant exported by this module called
*
* wakeupByPush
*
* you can use this constant to distinguish the app is launched
* by VoIP push notification or not
*
* e.g.
*/
if (VoipPushNotification.wakeupByPush) {
// do something...

// remember to set this static variable to false
// since the constant are exported only at initialization time
// and it will keep the same in the whole app
VoipPushNotification.wakeupByPush = false;
}

/**
* Local Notification Payload
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ var DEVICE_LOCAL_NOTIF_EVENT = 'voipLocalNotificationReceived';

export default class RNVoipPushNotification {

static wakeupByPush = (RNVoipPushNotificationManager.wakeupByPush === 'true');

/**
* Schedules the localNotification for immediate presentation.
*
Expand Down
32 changes: 29 additions & 3 deletions ios/RNVoipPushNotification/RNVoipPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,28 @@
#import "RCTEventDispatcher.h"
#import "RCTUtils.h"

NSString *const RNVoipRemoteNotificationsRegistered = @"VoipRemoteNotificationsRegistered";
NSString *const RNVoipLocalNotificationReceived = @"VoipLocalNotificationReceived";
NSString *const RNVoipRemoteNotificationReceived = @"VoipRemoteNotificationReceived";
NSString *const RNVoipRemoteNotificationsRegistered = @"voipRemoteNotificationsRegistered";
NSString *const RNVoipLocalNotificationReceived = @"voipLocalNotificationReceived";
NSString *const RNVoipRemoteNotificationReceived = @"voipRemoteNotificationReceived";

static NSString *RCTCurrentAppBackgroundState()
{
static NSDictionary *states;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
states = @{
@(UIApplicationStateActive): @"active",
@(UIApplicationStateBackground): @"background",
@(UIApplicationStateInactive): @"inactive"
};
});

if (RCTRunningInAppExtension()) {
return @"extension";
}

return states[@(RCTSharedApplication().applicationState)] ? : @"unknown";
}

@implementation RCTConvert (UILocalNotification)

Expand Down Expand Up @@ -64,6 +83,13 @@ - (void)setBridge:(RCTBridge *)bridge
object:nil];
}

- (NSDictionary<NSString *, id> *)constantsToExport
{
NSString *currentState = RCTCurrentAppBackgroundState();
NSLog(@"[RNVoipPushNotificationManager] constantsToExport currentState = %@", currentState);
return @{@"wakeupByPush": (currentState == @"background") ? @"true" : @"false"};
}

- (void)registerUserNotification:(NSDictionary *)permissions
{
UIUserNotificationType types = UIUserNotificationTypeNone;
Expand Down