Note: In Android, you must call initPush first, iOS doesn't need.
Common API for Android and iOS.
registrationId generated by JPush SDK according to deviceToken .
-
getRegistrationID(function)
JPushModule.getRegistrationID((registrationId) => {})
Stop push.
JPushModule.stopPush();
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) => {})
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(tags, callback)
JPushModule.deleteTags(['tag1', 'tag2'], (success) => {})
reset tags.
-
setTags(tags, successCallback)
JPushModule.setTags(['tag1','tag2'], (success) => {})
-
cleanTags(callback)
JPushModule.cleanTags((success) => {})
-
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' } )
- buildId : Number // set local notification styles,1 defoult style,2 custom style( you should call setStyleCustom frist) (Android Only)
Clear all notifications.
JPushModule.clearAllNotifications();
Clear notification by id(int type).
var id = 5;
JPushModule.clearNotificationById(id);
NOTE: iOS need update to jpush-react-native@2.0.0+
-
addReceiveOpenNotificationListener(function)
var callback = (map) => { } JPushModule.addReceiveOpenNotificationListener(callback);
-
removeReceiveOpenNotificationListener(function)
JPushModule.removeReceiveOpenNotificationListener(callback)
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(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);
All apis can find in jpush-react-native/index.js.
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];set application's badge.
JPushModule.setBadge(5, (success) => { } );get application's badge.
JPushModule.getBadge( (badge) => { } );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);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 by
addOpenNotificationLaunchAppListener.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,
removeOpenNotificationLaunchAppEventListenerandaddOpenNotificationLaunchAppListenerused 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 ,
setTagandsetAliasneeds to be called after network did login Event.var callback = () => { } JPushModule.addnetworkDidLoginListener(callback)
-
removenetworkDidLoginListener(function)
remove: JPush SDK did login event ,
removenetworkDidLoginListenerandaddnetworkDidLoginListenerused in pairs.
-
Init JPush。Suggest invokes in
MainActivity'sonCreatemethod:JPushInterface.init(this); -
Resume push. Suggest invokes in
MainActivity'sonResumemethod:JPushInterface.onResume(this); -
Stop upload crash log.
JPushModule.crashLogOFF(); -
Start upload crash log.
JPushModule.crashLogON(); -
Notify JPushModule complete init,send cached events.
JPushModule.notifyJSDidLoad((resultCode) => { }); -
Get device's infomation.
JPushModule.getInfo((map) => { }); -
Set notification's style to basic style.
JPushModule.setStyleBasic(); -
Set custom notification style. Need add custom xml file to Android resource.
JPushModule.setStyleCustom(); -
Set latest number of notifications. Default will show 5 latest notifications.
JPushModule.setLatestNotificationNumber(maxNumber); -
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); -
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) -
Remove listener.
removeGetRegistrationIdListenerandaddGetRegistrationIdListenershould used in pairs.JPushModule.removeGetRegistrationIdListener(callback);