49 行
1.4 KiB
Mathematica
49 行
1.4 KiB
Mathematica
|
|
#import <React/RCTBridgeModule.h>
|
||
|
|
#import <React/RCTEventEmitter.h>
|
||
|
|
|
||
|
|
@interface XuqmPushModule : RCTEventEmitter <RCTBridgeModule>
|
||
|
|
@end
|
||
|
|
|
||
|
|
@implementation XuqmPushModule
|
||
|
|
|
||
|
|
RCT_EXPORT_MODULE(XuqmPushModule);
|
||
|
|
|
||
|
|
- (NSArray<NSString *> *)supportedEvents {
|
||
|
|
return @[@"XuqmPushToken"];
|
||
|
|
}
|
||
|
|
|
||
|
|
+ (BOOL)requiresMainQueueSetup {
|
||
|
|
return NO;
|
||
|
|
}
|
||
|
|
|
||
|
|
RCT_EXPORT_METHOD(detectVendor:(RCTPromiseResolveBlock)resolve
|
||
|
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||
|
|
NSString *vendor = @"APNS";
|
||
|
|
#if TARGET_OS_SIMULATOR
|
||
|
|
vendor = @"FCM";
|
||
|
|
#endif
|
||
|
|
resolve(vendor);
|
||
|
|
}
|
||
|
|
|
||
|
|
RCT_EXPORT_METHOD(registerPush:(RCTPromiseResolveBlock)resolve
|
||
|
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||
|
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||
|
|
resolve(@(YES));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
// Called by the AppDelegate to report the device token
|
||
|
|
- (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
||
|
|
const unsigned char *dataBuffer = (const unsigned char *)[deviceToken bytes];
|
||
|
|
NSUInteger dataLength = [deviceToken length];
|
||
|
|
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)];
|
||
|
|
for (NSUInteger i = 0; i < dataLength; ++i) {
|
||
|
|
[hexString appendFormat:@"%02x", dataBuffer[i]];
|
||
|
|
}
|
||
|
|
NSString *token = [hexString copy];
|
||
|
|
[self sendEventWithName:@"XuqmPushToken" body:@{@"token": token, @"vendor": @"APNS"}];
|
||
|
|
}
|
||
|
|
|
||
|
|
@end
|