uniapp对接unipush 1.0 ios/android

配置

注意 需要打包自定义基座之后在手机上运行自定义基座 才可以! 官方有文档可以根据文档来
我这里用的是1.0 为什么没有2.0 因为2.0要用uinicloud
注意每次打包之后cid都会变
cid 用户的标识id uniapp通过这个id可以把消息推送给指定人

uniapp对接unipush 1.0 ios/android_第1张图片

前端代码

前端要做的很简单 直接放到app.vue中onLaunch钩子中即可
麻烦的在后端和个推的对接

 onPushMessage(that) {
		// #ifdef APP-PLUS
		uni.onPushMessage(res => {
			let platform = uni.getSystemInfoSync().platform;
			let {
				type,
				data: {
					payload = {}
				}
			} = res || {};
			let {
				title = '',
				content = '',
				path = ''
			} = payload;
			if (path) {
			//特殊判断如果是ios并且type == "receive" 手动创建消息推送
				if (platform == 'ios' && type == "receive") {
					uni.createPushMessage({
						title,
						content,
						payload,
						success() {
							console.log("推送成功");
						},
						fail() {
							console.log("推送失败");
						}
					})
					return
				}
				setTimeout(() => {
					that.$nextTick(() => {
						uni.navigateTo({
							url: path,
							fail() {
								uni.showToast({
									title: "跳转失败"
								})
							}
						})
					})
				}, 3000)
			}
		})
		//#endif 
	},

附上后端和个推的对接参数做参考

    request_id,
      settings: {
        ttl: 7200000,
      },
      audience: { 
        cid: [""],
      },
      //在线
      push_message: {
        notification: {
          title: "提示",
          body: "通知内容",
          big_text: "通知内容",
          channel_id: "Default",
          channel_name: "Default",
          channel_level: 4, 
          click_type: "payload",
          payload: JSON.stringify({
            title: "自定义消息内容在线通知",
            content: "自定义消息内容在线通知内容",
            path: "/Seting/index/index",
          }),
        },
      },
      //离线
      push_channel: {
        android: {
          ups: {
            notification: {
              title: "离线通知标题",
              body: "厂商通知内容",
              click_type: "intent",
              intent: `intent://io.dcloud.unipush/?#Intent;scheme=unipush;launchFlags=0x4000000;component=yunscs.com/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=;S.content=测试内容;S.payload={title: '自定义消息内容',path:'/pagesOrder/order/orderDetails?packageId=YSPAK24Q3082715134801N0981'};end`,
            },
            options: {
              VV: {
                "/extra/callback.id": "4712", //回执id  市场后台申请的
                "/category": "ORDER", //二级分类。 市场后台申请的
              },
              HW: {
                "/message/android/notification/badge/class":
                  "io.dcloud.PandoraEntry", //写死
                "/message/android/notification/badge/add_num": 1,
                "/message/android/category": "EXPRESS", // 注意这里 需要自己去每个app市场后台申请一下 要不然限制次数
              },
            },
          },
        },
        ios: {
          type: "notify",
          payload: JSON.stringify({
            title: "自定义消息内容离线通知",
            path: "/pagesOrder/order/orderDetails?packageId=YSPAK24Q3082715042801N5042",
          }),
          aps: {
            alert: {
              title: "通知标题",
              body: "通知内容",
            },
            "content-available": 0,
            sound: "default",
            category: "ACTIONABLE",
          },
          auto_badge: "+1",
        },
      },

你可能感兴趣的:(uni-app,ios,android)