2
0
mirror of synced 2025-01-23 04:39:49 +00:00

[ios] Add hasPermission method

This commit is contained in:
Chris Bianca 2018-02-05 18:04:10 +00:00
parent 93805062f7
commit b5b02ed84d
2 changed files with 31 additions and 13 deletions

View File

@ -212,6 +212,19 @@ RCT_EXPORT_METHOD(getInitialMessage:(RCTPromiseResolveBlock)resolve rejecter:(RC
resolve(nil);
}
}
RCT_EXPORT_METHOD(hasPermission: (RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) {
resolve(@([RCTSharedApplication() currentUserNotificationSettings].types != UIUserNotificationTypeNone));
} else {
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
resolve(@(settings.alertSetting == UNNotificationSettingEnabled));
}];
#endif
}
}
RCT_EXPORT_METHOD(sendMessage: (NSDictionary *) message
resolve:(RCTPromiseResolveBlock) resolve

View File

@ -13,28 +13,29 @@ import type App from '../core/firebase-app';
type Notification = {
body: string,
bodyLocalizationArgs: string[],
bodyLocalizationKey: string,
clickAction: string,
color: string,
icon: string,
link: string,
bodyLocalizationArgs?: string[],
bodyLocalizationKey?: string,
clickAction?: string,
color?: string,
icon?: string,
link?: string,
sound: string,
tag: string,
subtitle?: string,
tag?: string,
title: string,
titleLocalizationArgs: string[],
titleLocalizationKey: string,
titleLocalizationArgs?: string[],
titleLocalizationKey?: string,
};
type Message = {
collapseKey: string,
collapseKey?: string,
data: { [string]: string },
from: string,
from?: string,
messageId: string,
messageType?: string,
openedFromTray: boolean,
notification?: Notification,
sentTime: number,
sentTime?: number,
to?: string,
ttl?: number,
};
@ -54,7 +55,7 @@ type OnTokenRefreshObserver = {
type RemoteMessage = {
collapseKey?: string,
data: { [string]: string },
messageId?: string,
messageId: string,
messageType?: string,
to: string,
ttl: number,
@ -164,6 +165,10 @@ export default class Messaging extends ModuleBase {
return getNativeModule(this).getInitialMessage();
}
hasPermission(): Promise<boolean> {
return getNativeModule(this).hasPermission();
}
sendMessage(remoteMessage: RemoteMessage): Promise<void> {
return getNativeModule(this).send(remoteMessage);
}