index.d.ts 3.71 KB
Newer Older
1 2
declare module "react-native-fcm" {

Libin Lu's avatar
Libin Lu committed
3
    type FCMEventType = "FCMTokenRefreshed" | "FCMNotificationReceived" | 'FCMDirectChannelConnectionChanged';
4 5 6
    export module FCMEvent {
        const RefreshToken = "FCMTokenRefreshed";
        const Notification = "FCMNotificationReceived";
Libin Lu's avatar
Libin Lu committed
7
        const DirectChannelConnectionChanged: 'FCMDirectChannelConnectionChanged'
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    }

    export module RemoteNotificationResult {
        const NewData = "UIBackgroundFetchResultNewData";
        const NoData = "UIBackgroundFetchResultNoData";
        const ResultFailed = "UIBackgroundFetchResultFailed";
    }

    export module WillPresentNotificationResult {
        const All = "UNNotificationPresentationOptionAll";
        const None = "UNNotificationPresentationOptionNone";
    }

    export module NotificationType {
        const Remote = "remote_notification";
        const NotificationResponse = "notification_response";
        const WillPresent = "will_present_notification";
        const Local = "local_notification";
    }

Daniel Prado's avatar
Daniel Prado committed
28
    export interface Notification {
29 30 31 32 33 34 35 36
        collapse_key: string;
        opened_from_tray: boolean;
        from: string;
        notification: {
            title?: string
            body: string;
            icon: string;
        };
37 38 39 40 41 42 43 44
        fcm: {
            action?: string;
            tag?: string;
            icon?: string;
            color?: string;
            body: string;
            title?: string;
        };
45
        local_notification?: boolean;
46 47
        _notificationType: string;
        finish(type?: string): void;
Daniel Prado's avatar
Daniel Prado committed
48
        [key: string]: any;
49 50 51
    }

    export interface LocalNotification {
52
        id?: string;
53 54 55 56
        title?: string;
        body: string;
        icon?: string;
        vibrate?: number;
Baptiste MORELLE's avatar
Baptiste MORELLE committed
57
        sound?: string;
58
        big_text?: string;
59 60
        sub_text?: string;
        color?: string;
61
        large_icon?: string;
62 63 64
        priority?: string;
        show_in_foreground?: boolean;
        click_action?: string;
Libin Lu's avatar
Libin Lu committed
65
        badge?: number;
66 67 68 69 70
        number?: number;
        ticker?: string;
        auto_cancel?: boolean;
        group?: string;
        picture?: string;
Libin Lu's avatar
Libin Lu committed
71 72
        ongoing?: boolean;
        lights?: boolean;
Daniel Prado's avatar
Daniel Prado committed
73
        [key: string]: any;
74 75
    }

Daniel Prado's avatar
Daniel Prado committed
76
    export interface ScheduleLocalNotification extends LocalNotification {
77
        id: string;
78 79
        fire_date: number;
        repeat_interval?: "week" | "day" | "hour"
80 81
    }

82 83 84 85 86
    export interface Subscription {
        remove(): void;
    }

    export class FCM {
Libin Lu's avatar
Libin Lu committed
87
        static requestPermissions(): Promise<void>;
88 89
        static getFCMToken(): Promise<string>;
        static on(event: "FCMTokenRefreshed", handler: (token: string) => void): Subscription;
90
        static on(event: "FCMNotificationReceived", handler: (notification: Notification) => void): Subscription;
91 92
        static subscribeToTopic(topic: string): void;
        static unsubscribeFromTopic(topic: string): void;
93 94
        static getInitialNotification(): Promise<Notification>;
        static presentLocalNotification(notification: LocalNotification): void;
95

Libin Lu's avatar
Libin Lu committed
96
        static scheduleLocalNotification(schedule: ScheduleLocalNotification): void;
97
        static getScheduledLocalNotifications(): Promise<LocalNotification>;
98 99 100 101 102 103 104 105 106 107

        static removeAllDeliveredNotifications(): void;
        static removeDeliveredNotification(id: string): void;

        static cancelAllLocalNotifications(): void;
        static cancelLocalNotification(id: string): string;

        static setBadgeNumber(badge: number): void;
        static getBadgeNumber(): Promise<number>;
        static send(id: string, data: any): void;
Libin Lu's avatar
Libin Lu committed
108 109 110 111

        static enableDirectChannel(): void
        static isDirectChannelEstablished(): Promise<boolean>
        static getAPNSToken(): Promise<string>
112 113 114 115
    }

    export default FCM;
}