mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
[ReactNative] Put launchOptions in RCTPushNotificationManager
This commit is contained in:
12
ReactKit/Modules/RCTPushNotificationManager.h
Normal file
12
ReactKit/Modules/RCTPushNotificationManager.h
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#import <FBReactKit/RCTBridgeModule.h>
|
||||
|
||||
extern NSString *const RKRemoteNotificationReceived;
|
||||
extern NSString *const RKOpenURLNotification;
|
||||
|
||||
@interface RCTPushNotificationManager : NSObject <RCTBridgeModule>
|
||||
|
||||
- (instancetype)initWithInitialNotification:(NSDictionary *)initialNotification NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@end
|
||||
64
ReactKit/Modules/RCTPushNotificationManager.m
Normal file
64
ReactKit/Modules/RCTPushNotificationManager.m
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
#import "RCTPushNotificationManager.h"
|
||||
|
||||
#import "RCTAssert.h"
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
|
||||
NSString *const RKRemoteNotificationReceived = @"RemoteNotificationReceived";
|
||||
NSString *const RKOpenURLNotification = @"RKOpenURLNotification";
|
||||
|
||||
@implementation RCTPushNotificationManager
|
||||
{
|
||||
NSDictionary *_initialNotification;
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
return [self initWithInitialNotification:nil];
|
||||
}
|
||||
|
||||
- (instancetype)initWithInitialNotification:(NSDictionary *)initialNotification
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
_initialNotification = [initialNotification copy];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleRemoteNotificationReceived:)
|
||||
name:RKRemoteNotificationReceived
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleOpenURLNotification:)
|
||||
name:RKOpenURLNotification
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)handleRemoteNotificationReceived:(NSNotification *)notification
|
||||
{
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"remoteNotificationReceived"
|
||||
body:[notification userInfo]];
|
||||
}
|
||||
|
||||
- (void)handleOpenURLNotification:(NSNotification *)notification
|
||||
{
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"openURL"
|
||||
body:[notification userInfo]];
|
||||
}
|
||||
|
||||
- (NSDictionary *)constantsToExport
|
||||
{
|
||||
return @{
|
||||
@"initialNotification": _initialNotification ?: [NSNull null]
|
||||
};
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user