U Push

Title: uPush Description: uPush

立即使用

configUPush connect disconnect addUPushListener queryUnreadCount setCustomSound getDeviceType getDeviceId getUserId getUserType getPushState setPush setReceiverWarning getReceiverWarning notifyShow cancleNotify sdkNotify

概述

封装了建投统一推送SDK

如何使用远程推送

集成推送功能流程如下文所示。此过程中涉及到的 AppID 即为 Bundle Identifie,与 APICloud 平台上的包名是同一个东西,在 APICloud 平台上应用的概览里可以查看。

  1. 登录苹果开发者中心申请推送证书,本过程操作详情参考配置环信推送证书

  2. 将上一步生成的 p12 证书上传到推送SDK后台

  3. 将 1 过程中生成的 provisioning profile 文件和证书上传 APICloud 平台,即可在 APICloud 平台云编译出 ipa 安装包并安装(正式版发布到苹果商店,通过苹果商店下载安装)

以上步骤都已经实现后,还需要使用您 App 的用户允许通知,才能收到远程推送。您可以在设备的设置应用中,查看当前App是否允许通知。

使用此模块之前必须先配置 config 文件,配置方法如下:

  • 名称:uPush
  • 参数:umMessageSecret、miAppID、miAppKey
  • 配置示例:
  1. <feature name="uPush">
  2. <param name="umMessageSecret" value="" />
  3. <param name="miAppID" value="" />
  4. <param name="miAppKey" value="" />
  5. </feature>
  6. <meta-data
  7. android:name="com.huawei.hms.client.appid"
  8. android:value="*******" />
  • 字段描述:
  1. **umMessageSecret**: 友盟的 UMENG_MESSAGE_SECRET(仅android支持)
  2. **miAppID**: 小米appId,在小米推送开放平台获取(仅android支持)
  3. **miAppKey**:小米appKey,在小米开放平台获取(仅android支持)
  4. **com.huawei.hms.client.appid**: 华为appId,在华为推送开放平台获取(仅android支持)

铃声提醒、静音震动功能

默认系统提示音 默认 soundID == -1,即不开启铃声提醒,若要使用系统铃声提醒静音功能,请按下方注释传入相应soundID 注意:

  • 若未设置过soundID属性、setCustomSound方法和openShock属性, 则sdk默认不开启铃声提醒和设备静音震动功能

  • soundID进行了NSUserDefaults缓存,因此在app开发中,若使用到NSUserDefaults缓存策略,请不要使用soundID这个key

  • 因为soundID进行了NSUserDefaults缓存,因此不需要每次运行app都需要设置soundID属性、setCustomSound方法,但是若需要改变既有铃声需要重新赋值soundID属性调用系统铃声,或者执行setCustomSound方法自定义铃声,若要关闭铃声提醒功能,soundID = -1即可

  • 静音震动的openShock默认关闭静音震动,openShock = true则为开启,同样做了NSUserDefaults缓存策略,请不要使用openShock这个key

  • 因为soundID进行了NSUserDefaults缓存,因此不需要每次运行app都需要设置,但是若需要开启或关闭静音震动需要重新赋值openShock

使用系统自带声音,默认的推送三全音 id 是 1312 注意:系统声音部分会自带震动,比如1312是收到sms时的声音,会有自带震动,1305是lock锁屏声音,不会自带震动

soundID取值如下:

  • 1000 new-mail.caf new-mail.caf MailReceived
  • 1001 mail-sent.caf mail-sent.caf MailSent
  • 1002 Voicemail.caf Voicemail.caf VoicemailReceived
  • 1003 ReceivedMessage.caf ReceivedMessage.caf SMSReceived
  • 1004 SentMessage.caf SentMessage.caf SMSSent
  • 1005 alarm.caf sq_alarm.caf CalendarAlert
  • 1006 low_power.caf low_power.caf LowPower
  • 1007 sms-received1.caf sms-received1.caf SMSReceived_Alert
  • 1008 sms-received2.caf sms-received2.caf SMSReceived_Alert
  • 1009 sms-received3.caf sms-received3.caf SMSReceived_Alert
  • 1010 sms-received4.caf sms-received4.caf SMSReceived_Alert
  • 1011 - - SMSReceived_Vibrate
  • 1012 sms-received1.caf sms-received1.caf SMSReceived_Alert
  • 1013 sms-received5.caf sms-received5.caf SMSReceived_Alert
  • 1014 sms-received6.caf sms-received6.caf SMSReceived_Alert
  • 1015 Voicemail.caf Voicemail.caf - Available since 2.1
  • 1016 tweet_sent.caf tweet_sent.caf SMSSent Available since 5.0
  • 1020 Anticipate.caf Anticipate.caf SMSReceived_Alert Available since 4.2
  • 1021 Bloom.caf Bloom.caf SMSReceived_Alert Available since 4.2
  • 1022 Calypso.caf Calypso.caf SMSReceived_Alert Available since 4.2
  • 1023 Choo_Choo.caf Choo_Choo.caf SMSReceived_Alert Available since 4.2
  • 1024 Descent.caf Descent.caf SMSReceived_Alert Available since 4.2
  • 1025 Fanfare.caf Fanfare.caf SMSReceived_Alert Available since 4.2
  • 1026 Ladder.caf Ladder.caf SMSReceived_Alert Available since 4.2
  • 1027 Minuet.caf Minuet.caf SMSReceived_Alert Available since 4.2
  • 1028 News_Flash.caf News_Flash.caf SMSReceived_Alert Available since 4.2
  • 1029 Noir.caf Noir.caf SMSReceived_Alert Available since 4.2
  • 1030 Sherwood_Forest.caf Sherwood_Forest.caf SMSReceived_Alert Available since 4.2
  • 1031 Spell.caf Spell.caf SMSReceived_Alert Available since 4.2
  • 1032 Suspense.caf Suspense.caf SMSReceived_Alert Available since 4.2
  • 1033 Telegraph.caf Telegraph.caf SMSReceived_Alert Available since 4.2
  • 1034 Tiptoes.caf Tiptoes.caf SMSReceived_Alert Available since 4.2
  • 1035 Typewriters.caf Typewriters.caf SMSReceived_Alert Available since 4.2
  • 1036 Update.caf Update.caf SMSReceived_Alert Available since 4.2
  • 1050 ussd.caf ussd.caf USSDAlert
  • 1051 SIMToolkitCallDropped.caf SIMToolkitCallDropped.caf SIMToolkitTone
  • 1052 SIMToolkitGeneralBeep.caf SIMToolkitGeneralBeep.caf SIMToolkitTone
  • 1053 SIMToolkitNegativeACK.caf SIMToolkitNegativeACK.caf SIMToolkitTone
  • 1054 SIMToolkitPositiveACK.caf SIMToolkitPositiveACK.caf SIMToolkitTone
  • 1055 SIMToolkitSMS.caf SIMToolkitSMS.caf SIMToolkitTone
  • 1057 Tink.caf Tink.caf PINKeyPressed
  • 1070 ct-busy.caf ct-busy.caf AudioToneBusy There was no category for this sound before 4.0.
  • 1071 ct-congestion.caf ct-congestion.caf AudioToneCongestion There was no category for this sound before 4.0.
  • 1072 ct-path-ack.caf ct-path-ack.caf AudioTonePathAcknowledge There was no category for this sound before 4.0.
  • 1073 ct-error.caf ct-error.caf AudioToneError There was no category for this sound before 4.0.
  • 1074 ct-call-waiting.caf ct-call-waiting.caf AudioToneCallWaiting There was no category for this sound before 4.0.
  • 1075 ct-keytone2.caf ct-keytone2.caf AudioToneKey2 There was no category for this sound before 4.0.
  • 1100 lock.caf sq_lock.caf ScreenLocked
  • 1101 unlock.caf sq_lock.caf ScreenUnlocked
  • 1102 - - FailedUnlock
  • 1103 Tink.caf sq_tock.caf KeyPressed
  • 1104 Tock.caf sq_tock.caf KeyPressed
  • 1105 Tock.caf sq_tock.caf KeyPressed
  • 1106 beep-beep.caf sq_beep-beep.caf ConnectedToPower
  • 1107 RingerChanged.caf RingerChanged.caf RingerSwitchIndication
  • 1108 photoShutter.caf photoShutter.caf CameraShutter
  • 1109 shake.caf shake.caf ShakeToShuffle Available since 3.0
  • 1110 jbl_begin.caf jbl_begin.caf JBL_Begin Available since 3.0
  • 1111 jbl_confirm.caf jbl_confirm.caf JBL_Confirm Available since 3.0
  • 1112 jbl_cancel.caf jbl_cancel.caf JBL_Cancel Available since 3.0
  • 1113 begin_record.caf begin_record.caf BeginRecording Available since 3.0
  • 1114 end_record.caf end_record.caf EndRecording Available since 3.0
  • 1115 jbl_ambiguous.caf jbl_ambiguous.caf JBL_Ambiguous Available since 3.0
  • 1116 jbl_no_match.caf jbl_no_match.caf JBL_NoMatch Available since 3.0
  • 1117 begin_video_record.caf begin_video_record.caf BeginVideoRecording Available since 3.0
  • 1118 end_video_record.caf end_video_record.caf EndVideoRecording Available since 3.0
  • 1150 vc~invitation-accepted.caf vc~invitation-accepted.caf VCInvitationAccepted Available since 4.0
  • 1151 vc~ringing.caf vc~ringing.caf VCRinging Available since 4.0
  • 1152 vc~ended.caf vc~ended.caf VCEnded Available since 4.0
  • 1153 ct-call-waiting.caf ct-call-waiting.caf VCCallWaiting Available since 4.1
  • 1154 vc~ringing.caf vc~ringing.caf VCCallUpgrade Available since 4.1
  • 1200 dtmf-0.caf dtmf-0.caf TouchTone
  • 1201 dtmf-1.caf dtmf-1.caf TouchTone
  • 1202 dtmf-2.caf dtmf-2.caf TouchTone
  • 1203 dtmf-3.caf dtmf-3.caf TouchTone
  • 1204 dtmf-4.caf dtmf-4.caf TouchTone
  • 1205 dtmf-5.caf dtmf-5.caf TouchTone
  • 1206 dtmf-6.caf dtmf-6.caf TouchTone
  • 1207 dtmf-7.caf dtmf-7.caf TouchTone
  • 1208 dtmf-8.caf dtmf-8.caf TouchTone
  • 1209 dtmf-9.caf dtmf-9.caf TouchTone
  • 1210 dtmf-star.caf dtmf-star.caf TouchTone
  • 1211 dtmf-pound.caf dtmf-pound.caf TouchTone
  • 1254 long_low_short_high.caf long_low_short_high.caf Headset_StartCall
  • 1255 short_double_high.caf short_double_high.caf Headset_Redial
  • 1256 short_low_high.caf short_low_high.caf Headset_AnswerCall
  • 1257 short_double_low.caf short_double_low.caf Headset_EndCall
  • 1258 short_double_low.caf short_double_low.caf Headset_CallWaitingActions
  • 1259 middle_9_short_double_low.caf middle_9_short_double_low.caf Headset_TransitionEnd
  • 1300 Voicemail.caf Voicemail.caf SystemSoundPreview
  • 1301 ReceivedMessage.caf ReceivedMessage.caf SystemSoundPreview
  • 1302 new-mail.caf new-mail.caf SystemSoundPreview
  • 1303 mail-sent.caf mail-sent.caf SystemSoundPreview
  • 1304 alarm.caf sq_alarm.caf SystemSoundPreview
  • 1305 lock.caf sq_lock.caf SystemSoundPreview
  • 1306 Tock.caf sq_tock.caf KeyPressClickPreview The category was SystemSoundPreview before 3.2.
  • 1307 sms-received1.caf sms-received1.caf SMSReceived_Selection
  • 1308 sms-received2.caf sms-received2.caf SMSReceived_Selection
  • 1309 sms-received3.caf sms-received3.caf SMSReceived_Selection
  • 1310 sms-received4.caf sms-received4.caf SMSReceived_Selection
  • 1311 - - SMSReceived_Vibrate
  • 1312 sms-received1.caf sms-received1.caf SMSReceived_Selection
  • 1313 sms-received5.caf sms-received5.caf SMSReceived_Selection
  • 1314 sms-received6.caf sms-received6.caf SMSReceived_Selection
  • 1315 Voicemail.caf Voicemail.caf SystemSoundPreview Available since 2.1
  • 1320 Anticipate.caf Anticipate.caf SMSReceived_Selection Available since 4.2
  • 1321 Bloom.caf Bloom.caf SMSReceived_Selection Available since 4.2
  • 1322 Calypso.caf Calypso.caf SMSReceived_Selection Available since 4.2
  • 1323 Choo_Choo.caf Choo_Choo.caf SMSReceived_Selection Available since 4.2
  • 1324 Descent.caf Descent.caf SMSReceived_Selection Available since 4.2
  • 1325 Fanfare.caf Fanfare.caf SMSReceived_Selection Available since 4.2
  • 1326 Ladder.caf Ladder.caf SMSReceived_Selection Available since 4.2
  • 1327 Minuet.caf Minuet.caf SMSReceived_Selection Available since 4.2
  • 1328 News_Flash.caf News_Flash.caf SMSReceived_Selection Available since 4.2
  • 1329 Noir.caf Noir.caf SMSReceived_Selection Available since 4.2
  • 1330 Sherwood_Forest.caf Sherwood_Forest.caf SMSReceived_Selection Available since 4.2
  • 1331 Spell.caf Spell.caf SMSReceived_Selection Available since 4.2
  • 1332 Suspense.caf Suspense.caf SMSReceived_Selection Available since 4.2
  • 1333 Telegraph.caf Telegraph.caf SMSReceived_Selection Available since 4.2
  • 1334 Tiptoes.caf Tiptoes.caf SMSReceived_Selection Available since 4.2
  • 1335 Typewriters.caf Typewriters.caf SMSReceived_Selection Available since 4.2
  • 1336 Update.caf Update.caf SMSReceived_Selection Available since 4.2
  • 1350 - - RingerVibeChanged
  • 1351 - - SilentVibeChanged
  • 4095 - - Vibrate There was no category for this sound before 2.2.

代码中如何获取远程推送的内容

点击通知栏的远程推送时,如果此时 App 已经被系统冻结,则APICloud会将本次推送的内容通过事件监听回调的方式交给开发者。具体使用如下:

  1. api.addEventListener({
  2. name: 'noticeclicked'
  3. }, function(ret) {
  4. if (ret && ret.value) {
  5. var type = ret.type;//0:APICloud收到的推送内容,1:模块开发者自定义的
  6. var result = ret.value;//推送内容
  7. }
  8. })

如果 App 当前为活跃状态且未被系统冻结(按home键2分钟内app在后台运行状态),则您可通过在 addMessageListener 接口中监听 receive 事件捕获该消息,详情参考 addMessageListener 接口说明。此时若允许本地通知,则模块会弹出本地通知的提示框,用户点击该提示框,iOS系统会启动本App,同时api.addEventListener也会受到消息。

在Android平台,离线状态收到消息后,sdk会将消息已通知形式显示在手机状态栏(次通知不可自定义),当通知被点击后,APICloud会将本次推送的内容通过事件监听回调的方式交给开发者。具体使用如下:

  1. api.addEventListener({
  2. name: 'appintent'
  3. }, function(ret, err) {
  4. if (ret && ret.appParam.ajpush) {
  5. var msg = ret.uPushMessage;
  6. }
  7. })

Android 推送通道设置,不进行此设置android8.0以及以上系统可能收不到推送消息

  • 配置示例:
  1. <feature name="uPush">
  2. <param name="androidChannelId" value="11"/>
  3. <param name="androidChannel" value="appchannel"/>
  4. <param name="androidChannelDes" value="notification description"/>
  5. </feature>
  • 字段描述:

    androidChannelId:安卓8.0推送渠道配置,渠道id。后台通过此渠道id推送

    androidChannel:安卓8.0推送渠道配置,渠道名称。

    androidChannelDes:安卓8.0推送渠道配置,渠道描述

iOS证书

iOS端需要绑定的证书文件

制作方法如下:

下载 uPushAppendix 模块 zip 包并解压,把 zip 包内 target 目录下的 upush.der 文件替换为自己从建投统一推送平台获取的证书文件。然后重新压缩为 zip 包文件上传自定义模块,云编译时勾选该模块。

模块接口

configUPush

配置初始化推送SDK

configUPush({params},callback(ret, err))

params

host:

  • 类型:字符串类型
  • 描述:MQTT服务器地址

port:

  • 类型:字符串类型
  • 描述:MQTT服务器端口

deviceId:

  • 类型:字符串类型
  • 描述:设备id

deviceType:

  • 类型:数字类型
  • 描述:设备类型

appId:

  • 类型:字符串类型
  • 描述:appId

userName:

  • 类型:字符串类型
  • 描述:MQTT服务器需验证用户名

passWord:

  • 类型:字符串类型
  • 描述:MQTT服务器需验证密码

publishQos:

  • 类型:数字类型
  • 描述:(可选项)MQTT推消息型qos
  • 默认值:1

subscribeQos:

  • 类型:数字类型
  • 描述:(可选项)MQTT订阅型qos
  • 默认值:1

clean:

  • 类型:布尔类型
  • 描述:(可选项)是否清除MQTT缓存s(仅iOS支持)
  • 默认:false

openSSL:

  • 类型:布尔类型
  • 描述:(可选项)是否开启自签名证书SSL,若true,则下面的certificate需要配置证书名称(自签名证书是der后缀)(仅iOS支持)
  • 默认:true

certificate:

  • 类型:字符串类型
  • 描述:(可选项)自签名证书名称(仅iOS支持)

openShock:

  • 类型:布尔类型
  • 描述:(可选项)是否开启手机静音震动(仅iOS支持)
  • 默认:false

soundID:

  • 类型:数字类型
  • 描述:默认系统提示音,若要使用系统铃声提醒静音功能,请按下方说明传入相应soundID;默认 soundID == -1,即不开启铃声提醒,(仅iOS支持)
  • 默认:-1

useSDKPop:

  • 类型:布尔类型
  • 描述:(可选项)是否使用SDK内置消息弹框(仅iOS支持)
  • 默认:true

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.configUPush({
  3. host: '',
  4. port: '',
  5. deviceId: '',
  6. deviceType: 1
  7. appId: '',
  8. userName: '',
  9. publishQos: ,
  10. subscribeQos:
  11. });

可用性

iOS系统,Android系统

可提供的 1.0.0 及更高版本

connect

启动服务器连接

connect({params})

params

userId:

  • 类型:字符串类型
  • 描述:(可选项)用户Id,若userId为空,以未登录状态连接,若userId不空,以登录状态连接
  • 默认:空

userType:

  • 类型:数字类型
  • 描述:(可选项)用户类型
  • 默认:1

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.connect({
  3. userId: '',
  4. userType: 1
  5. });

可用性

iOS系统,Android系统

可提供的 1.0.0 及更高版本

disconnect

断开连接

disconnect(callback(ret,err))

params

userId:

  • 类型:字符串类型
  • 描述:(可选项)用户Id(仅android支持)
  • 默认:空

userType:

  • 类型:数字类型
  • 描述:(可选项)用户类型(仅android支持)
  • 默认:1

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:(仅android且 userId 不为空时返回)
  1. {
  2. status:, //布尔类型 ;是否成功
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.disconnect();

可用性

iOS系统,Android系统

可提供的 1.0.0 及更高版本

addUPushListener

添加uPush相关监听

addUPushListener(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. state: 'pushMessage', //字符串类型;相关事件,取值范围如下:
  3. //pushMessage:收到推送消息(仅iOS支持)
  4. //newMessage:接收到新消息
  5. //unreadMessageCount:获取未读消息条数
  6. //onlineSuccess:上线成功(仅iOS支持)
  7. //mState:获取连接状态
  8. pushInfo:{}, //json对象,推送消息字典对象,接收到推送消息时返回(仅iOS支持)
  9. msg:{}, //json对象,消息字典对象,可能为空,接收到新消息时返回(仅iOS支持)
  10. topic:'', //字符串类型;推送消息的主题,接收到新消息时返回(仅iOS支持)
  11. retained:true, //布尔类型;指示数据是否从服务器存储转发,接收到新消息时返回(仅iOS支持)
  12. count:0, //数字类型,未读消息条数,获取未读消息条数时返回(仅iOS支持)
  13. unReadMsg:'', //字符串类型;未读消息返回字符串 ,state为unreadMessageCount时返回(仅android支持)
  14. receiveMsg:'', //字符串类型;收到消息返回字符串,state为newMessage时返回(仅android支持)
  15. mState:0 //数字类型,连接状态,获取连接状态时返回
  16. //取值取下:
  17. //0:starting(仅iOS支持)
  18. //1:connecting(仅iOS支持)
  19. //2:error(仅iOS支持)
  20. //3:connected
  21. //4:closing(仅iOS支持)
  22. //5:closed
  23. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.addUPushListener(function(ret){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统,Android系统

可提供的1.0.0及更高版本

queryUnreadCount

获取未读数的主动调用方法

queryUnreadCount(callback(ret,err))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. status: true, //布尔类型;是否成功,true|false
  3. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. code:, //数字类型;错误码
  3. msg: '' //字符串类型;错误信息
  4. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.queryUnreadCount(function(ret,err){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统,Android系统

可提供的1.0.0及更高版本

setCustomSound

自定义铃声(仅iOS支持)

setCustomSound({params})

params

fileName:

  • 类型:字符串
  • 描述:铃声文件名,声音长度不能超过30秒

extension:

  • 类型:布尔
  • 描述:铃声文件扩展名

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.deleteConversation({
  3. fileName: '',
  4. extension: ''
  5. });

可用性

iOS系统

可提供的 1.0.0 及更高版本

getDeviceType

获取设备类型

getDeviceType(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. type:1, //数字类型;设备类型。小米 61, 华为 62 ,其他 60
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.getDeviceType(function(ret){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统,Android系统

可提供的1.0.0及更高版本

getDeviceId

获取设备Id

getDeviceId(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. deviceId:‘’, //字符串类型;设备Id
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.getDeviceId(function(ret){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统,Android系统

可提供的1.0.0及更高版本

getUserId

用于传递到h5消息中心的参数。当connect没有传入userId时,此方法返回deviceId,否则返回userId。

getUserId(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. userId:‘’, //字符串类型;用户Id
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.getUserId(function(ret){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统,Android系统

可提供的1.0.0及更高版本

getUserType

用于传递到h5消息中心的参数。当connect没有传入userType时,此方法返回deviceType(50),否则返回userType。

getUserType(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. userType:‘’, //数字类型;用户类型
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.getUserType(function(ret){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统,Android系统

可提供的1.0.0及更高版本

getPushState

获取当前是否可以接收通知及在线消息(仅iOS支持)

getPushState(callback(ret))

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. status: true, //布尔类型;是否可以接收通知及在线消息,true能, false不能
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.getPushState(function(ret){
  3. alert(JSON.stringify(ret));
  4. });

可用性

iOS系统

可提供的1.0.0及更高版本

setPush

通知设置

setPush({params})

params

enablePush:

  • 类型:布尔
  • 描述:(可选项)是否启用推送,true:启用能接收APNS通知,以及接收在线消息;false:禁用推送 关闭APNS通知,关闭在线消息,但是能查询未读数。
  • 默认:true

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.setPush({
  3. enablePush: true
  4. });

可用性

iOS系统,Android系统

可提供的 1.0.0 及更高版本

setReceiverWarning

设置在线提示声音或震动(仅android支持)

setReceiverWarning({params})

params

warning:

  • 类型:布尔类型
  • 描述:在线提示声音或震动
  • 默认:true

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.setReceiverWarning({
  3. warning: false
  4. });

可用性

Android系统

可提供的 1.0.0 及更高版本

getReceiverWarning

获取在线提示声音或震动(仅android支持)

getReceiverWarning({params,callBack(ret)})

callback(ret)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. warning: , //布尔类型;在线提示声音或震动
  3. }

示例代码

  1. var uPush = api.require('uPush');
  2. uPush.getReceiverWarning({
  3. },function(ret){
  4. alert(JSON.stringify(ret));
  5. });

可用性

Android系统

可提供的 1.0.0 及更高版本

notifyShow

显示自定义界面通知(仅android支持)

notifyShow({params},callback(ret))

params

notifyId:

  • 类型:数字类型
  • 描述:通知id,可根据此id关闭通知。id相同仅显示最后一个通知,id不同分别展示

title:

  • 类型:字符串类型
  • 描述:title

content:

  • 类型:字符串类型
  • 描述:内容

timeMillis:

  • 类型:数字类型
  • 描述:时间戳

extra:

  • 类型:字符串类型
  • 描述:(可选项)附加内容,会随点击事件回传

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. status:, //布尔类型;是否成功
  3. notifyId:, //数字类型;通知id
  4. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. msg:, //字符串类型;错误信息
  3. }

click

点击事件,点击会重新打开主页面并传递以下参数,参数通过api.addEventListener({name:’appintent’}接口监听

extra:

  • 类型:字符串类型
  • 描述:参数中附加内容

示例代码

  1. var planNotify = api.require('planNotify');
  2. planNotify.notifyShow({
  3. notifyId:10,
  4. title:'',
  5. content:'',
  6. }, function(ret, err) {
  7. alert(JSON.stringify(ret));
  8. });

可用性

Android系统

可提供的1.0.0及更高版本

cancleNotify

取消通知(仅android支持)

cancleNotify({params},callback(ret))

params

notifyId

  • 类型:数字类型
  • 描述:通知id,planRemind 接口中返回notifyId

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. status:, //布尔类型;是否关闭成功
  3. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. msg:, //字符串类型;错误信息
  3. }

示例代码

  1. var planNotify = api.require('planNotify');
  2. planNotify.cancleNotify({
  3. notifyId:,
  4. }, function(ret, err) {
  5. alert(JSON.stringify(ret));
  6. });

可用性

Android系统

可提供的1.0.0及更高版本

sdkNotify

sdk内在线消息提示(仅android支持)

sdkNotify({params},callback(ret))

params

messageData

  • 类型:字符串类型
  • 描述:消息内容,addUPushListener接口接收到新消息的消息字符串.

duration

  • 类型:数字类型
  • 描述:(可选项)显示时间,毫秒
  • 默认:5000

callback(ret, err)

ret:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. clickMessage:, //字符串类型;被点击消息内容,被点击后回调
  3. }

err:

  • 类型:JSON 对象
  • 内部字段:
  1. {
  2. msg:, //字符串类型;错误信息
  3. }

示例代码

  1. var planNotify = api.require('planNotify');
  2. planNotify.sdkNotify({
  3. messageData:"",
  4. }, function(ret, err) {
  5. alert(JSON.stringify(ret));
  6. });

可用性

Android系统

可提供的1.0.0及更高版本