Skip to content

Latest commit

 

History

History
431 lines (299 loc) · 10.6 KB

File metadata and controls

431 lines (299 loc) · 10.6 KB

中文文档

Note: In Android, you must call initPush first, iOS doesn't need.

Common API

Common API for Android and iOS.

getRegistrationID

registrationId generated by JPush SDK according to deviceToken .

  • getRegistrationID(function)

    JPushModule.getRegistrationID((registrationId) => {})

stopPush

Stop push.

JPushModule.stopPush();

setAlias

set device's application alias, you can push notificaiton with alias, every device can only have one alias.

  • setAlias(alias, successCallback)

    JPushModule.setAlias('alias', (success) => {})

addTags

use addTags to tag device , and can add many tag for you device, you can push remote notification with tag.

  • addTags(tags, callback)

    JPushModule.addTags(['tag1', 'tag2'], (success) => {})

deleteTags

  • deleteTags(tags, callback)

    JPushModule.deleteTags(['tag1', 'tag2'], (success) => {})

setTags

reset tags.

  • setTags(tags, successCallback)

    JPushModule.setTags(['tag1','tag2'], (success) => {})

cleanTags

  • cleanTags(callback)

    JPushModule.cleanTags((success) => {})

sendLocalNotification

  • sendLocalNotification(notification)

    • buildId : Number // set local notification styles,1 defoult style,2 custom style( you should call setStyleCustom frist) (Android Only)
      • id : Number // local notification identify,l you can use it to cancel local notification
    • title : String // local notification title
    • content : String // local notification content
    • extra : Object // local notification extra (key-value)
    • fireTime : Number // show local notification time(ms)
    • badge : Number // when local notification fire, application icon will set badge with this value (iOS Only)
    • sound : String // if you what to custom notification sound ,you should specify audio file name (iOS Only)
    • subtitle : String // set local notification subtitle (iOS10+ Only)
    var currentDate = new Date()
    JPushModule.sendLocalNotification(
        {
            id:5,
            content:'content',
            extra:{key1:'value1',key2:'value2'},
            fireTime: currentDate.getTime() + 3000,
            badge: 8,
            sound: 'fasdfa',
            subtitle: "subtitle",
            title: 'title'
        }
    )

clearAllNotifications

Clear all notifications.

JPushModule.clearAllNotifications();

clearNotificationById

Clear notification by id(int type).

var id = 5;
JPushModule.clearNotificationById(id);

Open Notification Event

NOTE: iOS need update to jpush-react-native@2.0.0+

  • addReceiveOpenNotificationListener(function)

    var callback = (map) => {
        }
    JPushModule.addReceiveOpenNotificationListener(callback);
  • removeReceiveOpenNotificationListener(function)

    JPushModule.removeReceiveOpenNotificationListener(callback)

Receive Notification Event

NOTE: iOS need update to jpush-react-native@2.0.0+

  • addReceiveNotificationListener(function)

    var callback = (event) => {
          console.log("alertContent: " + JSON.stringify(event));
    
    }
    JPushModule.addReceiveNotificationListener(callback);
  • removeReceiveNotificationListener(function)

    JPushModule.removeReceiveNotificationListener(callback);
    

Receive Custom Message Event

receive custom message(Add this listener to receive custom message.) NOTE: iOS need update to jpush-react-native@2.0.0+

  • addReceiveCustomMsgListener(function)

    var callback = (message) => {
          console.log("alertContent: " + JSON.stringify(message));
    
    }
    JPushModule.addReceiveCustomMsgListener(callback);
  • removeReceiveCustomMsgListener(function)

    JPushModule.removeReceiveCustomMsgListener(callback);

iOS Only API

All apis can find in jpush-react-native/index.js.

setupPush

register remote notification from system(will show request remote notification permission).

// AppDelegate.m 
JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
entity.types = UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound;
[JPUSHService registerForRemoteNotificationConfig:entity delegate:self];

setBadge

set application's badge.

  JPushModule.setBadge(5, (success) => { } );

getBadge

get application's badge.

  JPushModule.getBadge( (badge) => { } );

setLocalNotification

setLocalNotification(  Date,    		// date  local notification fire data
                       textContain,     // String local notification content
                       badge,           // int   after local notification fire will set application badge
                       alertAction,     // String alert notification button content
                       notificationKey, // String set local notification identify
                       userInfo,   		// Object notification extra key-value
                       soundName   		// String custom sound,set it to null will use defoult sound
         )
  JPushModule.setLocalNotification( this.state.date, 
                                    this.state.textContain,
                                    5, 
                                    'Action',
                                    'notificationIdentify',
                                    {myInfo: ""},
                                    null);

Open Notification Launch App Event

NOTE: iOS need update to jpush-react-native@2.0.0+

  • addOpenNotificationLaunchAppListener(function)

    add listener:application not running and tap notification to run application, will fire callback added byaddOpenNotificationLaunchAppListener .

    var callback = (notification) => {
    	console.log(JSON.stringify(nofitifation))
      }
    JPushModule.addOpenNotificationLaunchAppListener(callback)
  • removeOpenNotificationLaunchAppEventListener(function)

    JPushModule.removeOpenNotificationLaunchAppEventListener(callback)

    remove listener:application not running and tap notification to run application,removeOpenNotificationLaunchAppEventListener and addOpenNotificationLaunchAppListener used in pairs.

Network Did Login Event

NOTE: iOS need update to jpush-react-native@2.0.0+

  • addnetworkDidLoginListener(function)

    add listener: JPush SDK did login event ,setTag and setAlias needs to be called after network did login Event.

    var callback = () => {
      }
    JPushModule.addnetworkDidLoginListener(callback)
  • removenetworkDidLoginListener(function)

    remove: JPush SDK did login event ,removenetworkDidLoginListener and addnetworkDidLoginListener used in pairs.

Android Only API

  • initPush

    Init JPush。Suggest invokes in MainActivity 's onCreate method:

    JPushInterface.init(this);
    
  • resumePush

    Resume push. Suggest invokes in MainActivity 's onResume method:

    JPushInterface.onResume(this);
    
  • crashLogOFF

    Stop upload crash log.

    JPushModule.crashLogOFF();
    
  • crashLogON

    Start upload crash log.

    JPushModule.crashLogON();
    
  • notifyJSDidLoad

    Notify JPushModule complete init,send cached events.

    JPushModule.notifyJSDidLoad((resultCode) => {
    
    });
    
  • getInfo

    Get device's infomation.

    JPushModule.getInfo((map) => {
    });
    
  • setStyleBasic

    Set notification's style to basic style.

    JPushModule.setStyleBasic();
    
  • setStyleCustom

    Set custom notification style. Need add custom xml file to Android resource.

    JPushModule.setStyleCustom();
    
  • setLatestNotificationNumber

    Set latest number of notifications. Default will show 5 latest notifications.

    JPushModule.setLatestNotificationNumber(maxNumber);
    
  • setSilenceTime

    Set silence push time, will not push during these time.

    /**
     * Android Only
     * @param {object} config = {"startTime": String, "endTime": String}  // eg:{startTime: "20:30", endTime: "8:30"}
     */
    JPushModule.setSilenceTime(config);
    
  • setPushTime

    Set allow push time.

    /**
     * Android Only
     * @param {object} config = {"days": Array, "startHour": Number, "endHour": Number}  
     * // eg:{days: [0, 6], startHour: 8, endHour: 23} indicate push is allowed in 8 a.m. to 23 p.m. in satuaday and sunday.
     */
    JPushModule.setPushTime(config);
    

  • addGetRegistrationIdListener(^2.1.4 Deprecated, use getRegistrationId instead)

    If add this listener, when finished registering device, open app will invoke this callback.

    JPushModule.addGetRegistrationIdListener(cb)
    
  • removeGetRegistrationIdListener(^2.1.4 Deprecated)

    Remove listener. removeGetRegistrationIdListener and addGetRegistrationIdListener should used in pairs.

    JPushModule.removeGetRegistrationIdListener(callback);