React-native-onesignal: 打字稿打字

创建于 2018-04-03  ·  23评论  ·  资料来源: OneSignal/react-native-onesignal

嗨,伙计们,很棒的工作,你能添加打字稿支持吗?

我正在使用打字稿进行项目,但您不支持它:(

Enhancement / Feature

最有用的评论

你好@DavidNorena

您可以手动将此类型添加到您的项目中:

declare module 'react-native-onesignal' {

    enum InFocusDisplayOption {
        none = 0,
        inAppAlert = 1,
        notification = 2
    }

    enum LogLevel {
        None = 0,
        Fatal = 1,
        Errors = 2,
        Warnings = 3,
        Info = 4,
        Debug = 5,
        Verbose = 6
    }

    type oneSignalEvents = 'received' | 'opened' | 'ids';

    interface Settings {
        kOSSettingsKeyAutoPrompt: boolean,
        kOSSettingsKeyInAppLaunchURL: boolean,
        kOSSSettingsKeyPromptBeforeOpeningPushURL: boolean,
        kOSSettingsKeyInFocusDisplayOption: InFocusDisplayOption
    }

    interface PushData {
        notificationID: string,
        contentAvailable: boolean,
        badge?: number,
        sound: string,
        title: string,
        body: string,
        launchURL?: string,
        additionalData?: object,
        p2p_notification?: Array<any>
    }

    interface OpenResult {
        notification: {
            payload: PushData,
            isAppInFocus: boolean
        }
    }

    interface Permissions {
        alert: boolean,
        badge: boolean,
        sound: boolean
    }

    /**
     * shown If the notification was displayed to the user or not
     * payload the push data
     * displayType The display method of a received notification
     * silentNotification Wether the received notification was a silent one
     */
    interface ReceivedNotification {
        shown: boolean,
        payload: PushData,
        displayType: InFocusDisplayOption,
        silentNotification: boolean
    }


    export default class OneSignal {
        /**
         * Initialize Onesignal
         * <strong i="8">@param</strong> {string} appId Your app id you can get from OneSignal control panel.
         * <strong i="9">@param</strong> {"react-native-onesignal".Settings} settings (Optional) Settings for ios.
         */
        public static init(appId: string, settings?: Settings): void;

        /**
         * Undocumented function.
         */
        public static Configure( undocumentedParam1?: any, undocumentedParam2?: any) : void;

        /**
         * You can set tag for user with this function.
         * <strong i="10">@param</strong> {string} key Tag name you want to add to user.
         * <strong i="11">@param</strong> {string} value Tag value
         */
        public static sendTag(key: string, value: string): void;

        /**
         * You can set multiple tags for user with this function.
         * <strong i="12">@param</strong> {object} tags Tags you want to set. Sample: {key1: 'value1', key2: 'value2'}
         */
        public static sendTags(tags: object): void;

        /**
         * Getting the tags from the server and use the received object
         * <strong i="13">@param</strong> {Function} handler You can read tags from this parameter.
         */
        public static getTags(handler: (receivedTags: any) => {}): void;

        /**
         * Allows you to check whether notifications are enabled for the app, whether user is subscribed to notifications through OneSignal, and what the user's in-app subscription preference is. It also provides access to pushToken and userId
         * <strong i="14">@param</strong> {Function} handler Handler function you can read subscription status from first parameter.
         */
        public static getPermissionSubscriptionState(handler: (status: any) => {}): void;

        /**
         * You can delete tag from user with this function.
         * <strong i="15">@param</strong> {string} key Tag name you want to delete from user.
         */
        public static deleteTag(key: string): void;

        /**
         * OneSignal now allows you to send emails to your userbase. This email can be set using the OneSignal react-native SDK.
         * <strong i="16">@param</strong> {string} email User's email address.
         * <strong i="17">@param</strong> {string} emailAuthCode Email auth code should be securely generated by your backend server
         * <strong i="18">@param</strong> {Function} callback Handler function for error if it occurred
         */
        public static setEmail(email: string, emailAuthCode: string, callback: (error?: any) => {}): void;

        /**
         * If you don't want to implement email auth hashing on your backend (which is heavily recommended), you can still use the OneSignal email feature in an unauthenticated state with this function.
         * <strong i="19">@param</strong> {string} email User's email address.
         * <strong i="20">@param</strong> {Function} callback Handler function for error if it occurred
         */
        public static setEmail(email: string, callback: (error?: any) => {}): void;

        /**
         * If your application implements logout functionality, you can logout of the OneSignal email for this user using the logout function.
         * <strong i="21">@param</strong> {Function} callback Handler function for error if it occurred
         */
        public static logoutEmail(callback: (error?: any) => {}): void;

        /**
         * You can call this from your UI from a button press for example to give your user's options for your notifications. By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode. Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
         * <strong i="22">@param</strong> {boolean} setTo New value you want to set.
         */
        public static enableVibrate(setTo: boolean): void;

        /**
         * You can call this from your UI from a button press for example to give your user's options for your notifications. By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on. Passing false means that the device will only vibrate unless the device is set to a total silent mode.
         * <strong i="23">@param</strong> {boolean} setTo New value you want to set.
         */
        public static enableSound(setTo: boolean): void;

        /**
         * You can call this method with false to opt users out of receiving all notifications through OneSignal. You can pass true later to opt users back into notifications
         * <strong i="24">@param</strong> {boolean} setTo New value you want to set.
         */
        public static setSubscription(setTo: boolean): void;

        /**
         * Promts location permission to user.
         */
        public static promptLocation(): void;

        /**
         * Removes all OneSignal notifications from the Notification Shade.
         */
        public static clearOneSignalNotifications(): void;

        /**
         * Disable or enable location collection (defaults to enabled if your app has location permission).
         * <strong i="25">@param</strong> {boolean} setTo New value you want to set.
         */
        public static setLocationShared(setTo: boolean): void;

        /**
         * Prompts the user for location permissions. This allows for geotagging so you can send notifications to users based on location.
         *
         * Note: Make sure you also have the required location permission in your AndroidManifest.xml. For iOS, make sure you set the NSLocationWhenInUseUsageDescription or the NSLocationAlwaysUsageDescription in your info.plist. (Location Always also requires the location background mode capability)
         * <strong i="26">@param</strong> {"react-native-onesignal".InFocusDisplayOption} setTo New value you want to set.
         */
        public static inFocusDisplaying(setTo: InFocusDisplayOption): void;

        /**
         * P2P notification
         * <strong i="27">@param</strong> {object} contents Sample: { en: 'English Message', tr: 'Türkçe Mesaj' }
         * <strong i="28">@param</strong> {Array<any>} data Some array for payload
         * <strong i="29">@param</strong> {string} playerId OneSignal Player Id you want to send message to.
         * <strong i="30">@param</strong> {object} otherParameters Sample: {"ios_attachments" : {"image1" : "{image_url}"}}
         */
        public static postNotification(contents: object, data: Array<any>, playerId: string, otherParameters?: object): void;

        /**
         * Cancels a single OneSignal notification based on its Android notification integer id. You can get the notification Id when invoking OneSignal.onNotificationOpened while receiving a notification.
         * <strong i="31">@param</strong> {string} notificationId Notification id you want to cancel.
         */
        public static cancelNotification( notificationId: string ): void;

        /**
         * See what push permissions are currently enabled. callback will be invoked with a permissions object (currently supported only on iOS).
         * <strong i="32">@param</strong> {Function} callback Callback function you can read the permissions from first parameter.
         */
        public static checkPermissions( callback: (permissions: any) => {}): void;

        /**
         * Requests Push Notification Permissions (iOS Only)
         * <strong i="33">@param</strong> {"react-native-onesignal".Permissions} permissions Permissions you want to ask.
         */
        public static requestPermissions( permissions: Permissions ): void;

        /**
         * Call when you want to prompt the user to accept push notifications. Only call once and only if you passed <strong i="34">@NO</strong> to kOSSettingsKeyAutoPrompt on init.
         */
        public static registerForPushNotifications(): void;

        /**
         * IMPORTANT: Use this function before OneSignal.init
         *
         * Allows you to delay the initialization of the SDK until the user provides privacy consent. The SDK will not be fully initialized until the provideUserConsent(true) method is called.
         *
         * If you set this to be true, the SDK will not fully initialize until consent is provided. You can still call OneSignal methods, but nothing will happen, and the user will not be registered for push notifications.
         * <strong i="35">@param</strong> {boolean} wtf I don't know why this function asking boolean parameter. Just pass true if you don't know what you are doing.
         */
        public static setRequiresUserPrivacyConsent(wtf: boolean): void;

        /**
         * Will initialize the SDK and register for push notifications.
         * <strong i="36">@param</strong> {boolean} wtf I don't know why this function asking boolean parameter. Just pass true if you don't know what you are doing.
         */
        public static provideUserConsent(wtf: boolean): void;

        /**
         * Enable logging to help debug if you run into an issue setting up OneSignal.
         * <strong i="37">@param</strong> {"react-native-onesignal".LogLevel} logLevel Sets the logging level to print to the iOS Xcode log or the Android LogCat log.
         * <strong i="38">@param</strong> {"react-native-onesignal".LogLevel} visualLevel Sets the logging level to show as alert dialogs.
         */
        public static setLogLevel( logLevel: LogLevel, visualLevel: LogLevel ): void;

        /**
         * You can bind events with this function.
         * <strong i="39">@param</strong> {"react-native-onesignal".oneSignalEvents} type Event type you want to subscribe
         * <strong i="40">@param</strong> {Function} handler Handler function
         */
        public static addEventListener(type: oneSignalEvents, handler: Function): void;

        /**
         * You can remove binded events with this function.
         * <strong i="41">@param</strong> {"react-native-onesignal".oneSignalEvents} type Event type you want to subscribe
         * <strong i="42">@param</strong> {Function} handler (Optional) Handler function for solo remove.
         */
        public static removeEventListener(type: oneSignalEvents, handler?: Function): void;
    }
}

所有23条评论

我也是,onesignal 不是在响应原生打字稿吗?

@sionnita ,您可以在打字稿文件(.tsx、.ts)中使用它,使用 vainilla javascript,如文档中所述,但您将失去 IDE 类型和自动完成支持! 如果你使用 tslint 你会有很多错误和警告,这就是我要求定义文件的原因。

我还没有测试过,但似乎几个月前@krystofcelba创建了一个拉取请求 #395,他在其中添加了TypeScript 类型,但我认为不完整或不兼容,因为整个拉取请求没有'由于这个原因,不要让它成为分支主。

也许@krystofcelba或其他人可以帮助我们仅拉取打字稿定义文件的请求,我会这样做,但现在没有时间这样做:(

伙计们,美好的一天!

你好@DavidNorena

您可以手动将此类型添加到您的项目中:

declare module 'react-native-onesignal' {

    enum InFocusDisplayOption {
        none = 0,
        inAppAlert = 1,
        notification = 2
    }

    enum LogLevel {
        None = 0,
        Fatal = 1,
        Errors = 2,
        Warnings = 3,
        Info = 4,
        Debug = 5,
        Verbose = 6
    }

    type oneSignalEvents = 'received' | 'opened' | 'ids';

    interface Settings {
        kOSSettingsKeyAutoPrompt: boolean,
        kOSSettingsKeyInAppLaunchURL: boolean,
        kOSSSettingsKeyPromptBeforeOpeningPushURL: boolean,
        kOSSettingsKeyInFocusDisplayOption: InFocusDisplayOption
    }

    interface PushData {
        notificationID: string,
        contentAvailable: boolean,
        badge?: number,
        sound: string,
        title: string,
        body: string,
        launchURL?: string,
        additionalData?: object,
        p2p_notification?: Array<any>
    }

    interface OpenResult {
        notification: {
            payload: PushData,
            isAppInFocus: boolean
        }
    }

    interface Permissions {
        alert: boolean,
        badge: boolean,
        sound: boolean
    }

    /**
     * shown If the notification was displayed to the user or not
     * payload the push data
     * displayType The display method of a received notification
     * silentNotification Wether the received notification was a silent one
     */
    interface ReceivedNotification {
        shown: boolean,
        payload: PushData,
        displayType: InFocusDisplayOption,
        silentNotification: boolean
    }


    export default class OneSignal {
        /**
         * Initialize Onesignal
         * <strong i="8">@param</strong> {string} appId Your app id you can get from OneSignal control panel.
         * <strong i="9">@param</strong> {"react-native-onesignal".Settings} settings (Optional) Settings for ios.
         */
        public static init(appId: string, settings?: Settings): void;

        /**
         * Undocumented function.
         */
        public static Configure( undocumentedParam1?: any, undocumentedParam2?: any) : void;

        /**
         * You can set tag for user with this function.
         * <strong i="10">@param</strong> {string} key Tag name you want to add to user.
         * <strong i="11">@param</strong> {string} value Tag value
         */
        public static sendTag(key: string, value: string): void;

        /**
         * You can set multiple tags for user with this function.
         * <strong i="12">@param</strong> {object} tags Tags you want to set. Sample: {key1: 'value1', key2: 'value2'}
         */
        public static sendTags(tags: object): void;

        /**
         * Getting the tags from the server and use the received object
         * <strong i="13">@param</strong> {Function} handler You can read tags from this parameter.
         */
        public static getTags(handler: (receivedTags: any) => {}): void;

        /**
         * Allows you to check whether notifications are enabled for the app, whether user is subscribed to notifications through OneSignal, and what the user's in-app subscription preference is. It also provides access to pushToken and userId
         * <strong i="14">@param</strong> {Function} handler Handler function you can read subscription status from first parameter.
         */
        public static getPermissionSubscriptionState(handler: (status: any) => {}): void;

        /**
         * You can delete tag from user with this function.
         * <strong i="15">@param</strong> {string} key Tag name you want to delete from user.
         */
        public static deleteTag(key: string): void;

        /**
         * OneSignal now allows you to send emails to your userbase. This email can be set using the OneSignal react-native SDK.
         * <strong i="16">@param</strong> {string} email User's email address.
         * <strong i="17">@param</strong> {string} emailAuthCode Email auth code should be securely generated by your backend server
         * <strong i="18">@param</strong> {Function} callback Handler function for error if it occurred
         */
        public static setEmail(email: string, emailAuthCode: string, callback: (error?: any) => {}): void;

        /**
         * If you don't want to implement email auth hashing on your backend (which is heavily recommended), you can still use the OneSignal email feature in an unauthenticated state with this function.
         * <strong i="19">@param</strong> {string} email User's email address.
         * <strong i="20">@param</strong> {Function} callback Handler function for error if it occurred
         */
        public static setEmail(email: string, callback: (error?: any) => {}): void;

        /**
         * If your application implements logout functionality, you can logout of the OneSignal email for this user using the logout function.
         * <strong i="21">@param</strong> {Function} callback Handler function for error if it occurred
         */
        public static logoutEmail(callback: (error?: any) => {}): void;

        /**
         * You can call this from your UI from a button press for example to give your user's options for your notifications. By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode. Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
         * <strong i="22">@param</strong> {boolean} setTo New value you want to set.
         */
        public static enableVibrate(setTo: boolean): void;

        /**
         * You can call this from your UI from a button press for example to give your user's options for your notifications. By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on. Passing false means that the device will only vibrate unless the device is set to a total silent mode.
         * <strong i="23">@param</strong> {boolean} setTo New value you want to set.
         */
        public static enableSound(setTo: boolean): void;

        /**
         * You can call this method with false to opt users out of receiving all notifications through OneSignal. You can pass true later to opt users back into notifications
         * <strong i="24">@param</strong> {boolean} setTo New value you want to set.
         */
        public static setSubscription(setTo: boolean): void;

        /**
         * Promts location permission to user.
         */
        public static promptLocation(): void;

        /**
         * Removes all OneSignal notifications from the Notification Shade.
         */
        public static clearOneSignalNotifications(): void;

        /**
         * Disable or enable location collection (defaults to enabled if your app has location permission).
         * <strong i="25">@param</strong> {boolean} setTo New value you want to set.
         */
        public static setLocationShared(setTo: boolean): void;

        /**
         * Prompts the user for location permissions. This allows for geotagging so you can send notifications to users based on location.
         *
         * Note: Make sure you also have the required location permission in your AndroidManifest.xml. For iOS, make sure you set the NSLocationWhenInUseUsageDescription or the NSLocationAlwaysUsageDescription in your info.plist. (Location Always also requires the location background mode capability)
         * <strong i="26">@param</strong> {"react-native-onesignal".InFocusDisplayOption} setTo New value you want to set.
         */
        public static inFocusDisplaying(setTo: InFocusDisplayOption): void;

        /**
         * P2P notification
         * <strong i="27">@param</strong> {object} contents Sample: { en: 'English Message', tr: 'Türkçe Mesaj' }
         * <strong i="28">@param</strong> {Array<any>} data Some array for payload
         * <strong i="29">@param</strong> {string} playerId OneSignal Player Id you want to send message to.
         * <strong i="30">@param</strong> {object} otherParameters Sample: {"ios_attachments" : {"image1" : "{image_url}"}}
         */
        public static postNotification(contents: object, data: Array<any>, playerId: string, otherParameters?: object): void;

        /**
         * Cancels a single OneSignal notification based on its Android notification integer id. You can get the notification Id when invoking OneSignal.onNotificationOpened while receiving a notification.
         * <strong i="31">@param</strong> {string} notificationId Notification id you want to cancel.
         */
        public static cancelNotification( notificationId: string ): void;

        /**
         * See what push permissions are currently enabled. callback will be invoked with a permissions object (currently supported only on iOS).
         * <strong i="32">@param</strong> {Function} callback Callback function you can read the permissions from first parameter.
         */
        public static checkPermissions( callback: (permissions: any) => {}): void;

        /**
         * Requests Push Notification Permissions (iOS Only)
         * <strong i="33">@param</strong> {"react-native-onesignal".Permissions} permissions Permissions you want to ask.
         */
        public static requestPermissions( permissions: Permissions ): void;

        /**
         * Call when you want to prompt the user to accept push notifications. Only call once and only if you passed <strong i="34">@NO</strong> to kOSSettingsKeyAutoPrompt on init.
         */
        public static registerForPushNotifications(): void;

        /**
         * IMPORTANT: Use this function before OneSignal.init
         *
         * Allows you to delay the initialization of the SDK until the user provides privacy consent. The SDK will not be fully initialized until the provideUserConsent(true) method is called.
         *
         * If you set this to be true, the SDK will not fully initialize until consent is provided. You can still call OneSignal methods, but nothing will happen, and the user will not be registered for push notifications.
         * <strong i="35">@param</strong> {boolean} wtf I don't know why this function asking boolean parameter. Just pass true if you don't know what you are doing.
         */
        public static setRequiresUserPrivacyConsent(wtf: boolean): void;

        /**
         * Will initialize the SDK and register for push notifications.
         * <strong i="36">@param</strong> {boolean} wtf I don't know why this function asking boolean parameter. Just pass true if you don't know what you are doing.
         */
        public static provideUserConsent(wtf: boolean): void;

        /**
         * Enable logging to help debug if you run into an issue setting up OneSignal.
         * <strong i="37">@param</strong> {"react-native-onesignal".LogLevel} logLevel Sets the logging level to print to the iOS Xcode log or the Android LogCat log.
         * <strong i="38">@param</strong> {"react-native-onesignal".LogLevel} visualLevel Sets the logging level to show as alert dialogs.
         */
        public static setLogLevel( logLevel: LogLevel, visualLevel: LogLevel ): void;

        /**
         * You can bind events with this function.
         * <strong i="39">@param</strong> {"react-native-onesignal".oneSignalEvents} type Event type you want to subscribe
         * <strong i="40">@param</strong> {Function} handler Handler function
         */
        public static addEventListener(type: oneSignalEvents, handler: Function): void;

        /**
         * You can remove binded events with this function.
         * <strong i="41">@param</strong> {"react-native-onesignal".oneSignalEvents} type Event type you want to subscribe
         * <strong i="42">@param</strong> {Function} handler (Optional) Handler function for solo remove.
         */
        public static removeEventListener(type: oneSignalEvents, handler?: Function): void;
    }
}

@centrual 非常感谢!

敬启者; 我将此提交给了绝对类型的 repo。
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/30858

@FabianMeul感谢您的努力! 这似乎有待进行一些简单的修改。 你会很快跟进,还是应该从你的 PR 下载文件?

@centrual谢谢你

@centrual能否请您做一个 PR 并直接将类型添加到库中。

为什么关门了? OneSignal 是否会添加打字稿支持?

关注@chasemac问题

“不”是一个有效的答案:)
我想我们都只是想知道我们是否能够依赖这个包的类型。

尤其是考虑到这是第三方盈利公司的整合。
谢谢你🙆‍♂

@sospedra它已重新开放!

@rgomezp需要帮助吗?

@索斯佩德拉
总是。 随意打开一个拉取请求以供审查

@rgomezp我知道你们需要经营一家企业并专注于您的收入流(同时支持数十万个免费帐户)但是您能否促进/监督一个赏金计划,以便社区可以投入 5 美元到资助工作? 我相信你至少有 1K 的 Typescript 用户愿意参与进来。

“提交 PR”方法的问题在于,我们也在经营自己的业务,而获得 PR 批准的来回过程并不符合成本/时间效率。

更新:我创建了分支typescript-typings ,社区可以在其中帮助构建 SDK 的类型。 感谢大家的贡献!

分支: https :

绝对类型 PR: https :

-----(编辑)我认为这是过时的------

我不得不修改(addEventListener 和设置)从绝对类型/肯定类型#30858 让它工作,但我不想经历公关中涉及的所有官僚作风。

@rgomezp

如果有人想要这里的 copypasta,那就是

// Type definitions for react-native-onesignal 3.2
// Project: https://github.com/geektimecoil/react-native-onesignal#readme
// Definitions by: Krystof Celba <https://github.com/krystofcelba>
//                 Fabian Meul <https://github.com/FabianMeul>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
declare module 'react-native-onesignal' {
  export enum InFocusDisplayOption {
    none = 0,
    inAppAlert = 1,
    notification = 2,
  }

  export enum LogLevel {
    None = 0,
    Fatal = 1,
    Errors = 2,
    Warnings = 3,
    Info = 4,
    Debug = 5,
    Verbose = 6,
  }

  export type oneSignalEvents = 'received' | 'opened' | 'ids';

  export interface Settings {
    kOSSettingsKeyAutoPrompt?: boolean;
    kOSSettingsKeyInAppLaunchURL?: boolean;
    kOSSSettingsKeyPromptBeforeOpeningPushURL?: boolean;
    kOSSettingsKeyInFocusDisplayOption?: InFocusDisplayOption;
  }

  export interface PushData {
    notificationID: string;
    contentAvailable: boolean;
    badge?: number;
    sound: string;
    title: string;
    body: string;
    launchURL?: string;
    additionalData?: any;
    p2p_notification?: any[];
  }

  export interface OpenResult {
    notification: {
      payload: PushData;
      isAppInFocus: boolean;
    };
  }

  export interface Permissions {
    alert: boolean;
    badge: boolean;
    sound: boolean;
  }

  /**
   * shown If the notification was displayed to the user or not
   * payload the push data
   * displayType The display method of a received notification
   * silentNotification Wether the received notification was a silent one
   */
  export interface ReceivedNotification {
    shown: boolean;
    payload: PushData;
    displayType: InFocusDisplayOption;
    silentNotification: boolean;
  }

  export interface OneSignal {
    /**
     * Initialize Onesignal
     */
    init(appId: string, settings?: Settings): void;

    /**
     * Undocumented function.
     */
    Configure(undocumentedParam1?: any, undocumentedParam2?: any): void;

    /**
     * You can set tag for user with this function.
     */
    sendTag(key: string, value: string): void;

    /**
     * You can set multiple tags for user with this function.
     */
    sendTags(tags: object): void;

    /**
     * Getting the tags from the server and use the received object
     */
    getTags(handler: (receivedTags: any) => {}): void;

    /**
     * Allows you to check whether notifications are enabled for the app, whether user is subscribed to notifications through OneSignal,and what the user's in-app subscription preference is.
     * It also provides access to pushToken and userId
     */
    getPermissionSubscriptionState(handler: (status: any) => {}): void;

    /**
     * You can delete tag from user with this function.
     */
    deleteTag(key: string): void;

    /**
     * OneSignal now allows you to send emails to your userbase. This email can be set using the OneSignal react-native SDK.
     */
    setEmail(
      email: string,
      emailAuthCode: string,
      callback: (error?: any) => {},
    ): void;

    /**
     * If you don't want to implement email auth hashing on your backend (which is heavily recommended), you can still use the OneSignal email feature in an unauthenticated state with this function.
     */
    setEmail(email: string, callback: (error?: any) => {}): void;

    /**
     * If your application implements logout functionality, you can logout of the OneSignal email for this user using the logout function.
     */
    logoutEmail(callback: (error?: any) => {}): void;

    /**
     * You can call this from your UI from a button press for example to give your user's options for your notifications.
     * By default OneSignal always vibrates the device when a notification is displayed unless the device is in a total silent mode.
     * Passing false means that the device will only vibrate lightly when the device is in it's vibrate only mode.
     */
    enableVibrate(setTo: boolean): void;

    /**
     * You can call this from your UI from a button press for example to give your user's options for your notifications.
     * By default OneSignal plays the system's default notification sound when the device's notification system volume is turned on.
     * Passing false means that the device will only vibrate unless the device is set to a total silent mode.
     */
    enableSound(setTo: boolean): void;

    /**
     * You can call this method with false to opt users out of receiving all notifications through OneSignal.
     * You can pass true later to opt users back into notifications
     */
    setSubscription(setTo: boolean): void;

    /**
     * Promts location permission to user.
     */
    promptLocation(): void;

    /**
     * Removes all OneSignal notifications from the Notification Shade.
     */
    clearOneSignalNotifications(): void;

    /**
     * Disable or enable location collection (defaults to enabled if your app has location permission).
     */
    setLocationShared(setTo: boolean): void;

    /**
     * Prompts the user for location permissions. This allows for geotagging so you can send notifications to users based on location.
     *
     * Note: Make sure you also have the required location permission in your AndroidManifest.xml.
     * For iOS, make sure you set the NSLocationWhenInUseUsageDescription or the NSLocationAlwaysUsageDescription in your info.plist.
     * (Location Always also requires the location background mode capability)
     */
    inFocusDisplaying(setTo: InFocusDisplayOption): void;

    /**
     * P2P notification
     */
    postNotification(
      contents: object,
      data: any[],
      playerId: string,
      otherParameters?: object,
    ): void;

    /**
     * Cancels a single OneSignal notification based on its Android notification integer id.
     * You can get the notification Id when invoking OneSignal.onNotificationOpened while receiving a notification.
     */
    cancelNotification(notificationId: string): void;

    /**
     * See what push permissions are currently enabled. callback will be invoked with a permissions object (currently supported only on iOS).
     */
    checkPermissions(callback: (permissions: any) => {}): void;

    /**
     * Requests Push Notification Permissions (iOS Only)
     */
    requestPermissions(permissions: Permissions): void;

    /**
     * Call when you want to prompt the user to accept push notifications. Only call once and only if you passed <strong i="11">@NO</strong> to kOSSettingsKeyAutoPrompt on init.
     */
    registerForPushNotifications(): void;

    /**
     * IMPORTANT: Use this function before OneSignal.init
     *
     * Allows you to delay the initialization of the SDK until the user provides privacy consent. The SDK will not be fully initialized until the provideUserConsent(true) method is called.
     *
     * If you set this to be true, the SDK will not fully initialize until consent is provided.
     * You can still call OneSignal methods, but nothing will happen, and the user will not be registered for push notifications.
     */
    setRequiresUserPrivacyConsent(wtf: boolean): void;

    /**
     * Will initialize the SDK and register for push notifications.
     */
    provideUserConsent(wtf: boolean): void;

    /**
     * Enable logging to help debug if you run into an issue setting up OneSignal.
     */
    setLogLevel(logLevel: LogLevel, visualLevel: LogLevel): void;

    /**
     * You can bind events with this function.
     */
    addEventListener(
      type: 'received',
      handler: (notification: ReceivedNotification) => void,
    ): void;
    addEventListener(
      type: 'opened',
      handler: (result: OpenResult) => void,
    ): void;
    addEventListener(type: 'ids', handler: (device: string) => void): void;

    /**
     * You can remove binded events with this function.
     */
    removeEventListener(
      type: 'received',
      handler: (notification: ReceivedNotification) => void,
    ): void;
    removeEventListener(
      type: 'opened',
      handler: (result: OpenResult) => void,
    ): void;
    removeEventListener(type: 'ids', handler: (device: string) => void): void;
  }

  const OneSignal: OneSignal;

  export default OneSignal;
}

为什么默认情况下不安装 npm ? 我们不能快点吗?
TS 是我们日常使用的

对于任何想知道的人来说,这些类型似乎不再是最新的,所以不要盲目相信它们

关于我们何时可以期望类型成为包@rgomezp 的一部分,是否有任何更新? 我认为有很多人在那里构建基于 TS 的 RN 应用程序,并且通过包添加和维护它会很棒。 谢谢!

你好@taschik
我目前正在研究类型(请参阅分支types ),这将成为即将发布的主要版本的一部分。

棒极了! 感谢@rgomezp的出色工作和快速更新。 👏

PSA: types分支已合并到major-release

请查看 #1079 并提供反馈或报告任何打字问题(如果您遇到任何问题)。

你好,
打字现在作为beta.4版本的一部分提供。

"dependencies": {
    "react-native-onesignal": "^4.0.0-beta.4"
}

此处了解有关 Beta 的更多信息。

享受!

此页面是否有帮助?
0 / 5 - 0 等级