uniapp接入极光推送

极光推送用的是第三方的云端插件,推送和认证一般都差不多,以下为引入步骤:
插件地址:https://ext.dcloud.net.cn/plugin?id=741
1.引入插件到项目(此插件正式对接时需要购买)我在这里接的是试用版本

1607571043(1).jpg

2.从极光后台获取appkey,然后填入下方位置


1607570991(1).jpg

3.配置完后打自定义包


image.png

4.打包的时候用自有证书,(前提要在极光后台配置好,一般配置信息只需要个包名和签名),


image.png

5.打包完成后就可以直接真机预览了,预览的时候选择自己的基座


image.png

6.以上准备工作就完成了,接下来直接根据插件给的api测试就可以了,下图是我测试时候的代码

<template>
    <view class="content">
        <image class="logo" src="/static/logo.png"></image>
        <view class="text-area"><button type="default">授权1</button></view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            jyJPush: []
        };
    },
    onReady() {
        this.jyJPush = uni.requireNativePlugin('JY-JPush');
        this.jyJPush.setJYJPushAlias(
            {
                userAlias: 'testAlias'
            },
            result => {
                console.log(result);
                //  设置成功或者失败,都会通过这个result回调返回数据;数据格式保持极光返回的安卓/iOS数据一致
                //  注:若没有返回任何数据,考虑是否初始化完成
                // uni.showToast({
                //  icon: 'none',
                //  title: JSON.stringify(result)
                // });
            }
        );
        this.jyJPush.addJYJPushReceiveNotificationListener(result => {
            console.log(result);
            //  监听成功后,若收到推送,会在result返回对应的数据;数据格式保持极光返回的安卓/iOS数据一致
            uni.showToast({
                icon: 'none',
                title: JSON.stringify(result.notificationContent)
            });
        });
        this.jyJPush.addJYJPushReceiveOpenNotificationListener(result => {
            //  监听成功后,若点击推送消息,会触发result;数据格式保持极光返回的安卓/iOS数据一致
            uni.showToast({
                icon: 'none',
                title: JSON.stringify(result.notificationContent)
            });
        });
    },
    methods: {}
};
</script>

<style>
.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    height: 200rpx;
    width: 200rpx;
    margin-top: 200rpx;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 50rpx;
}

.text-area {
    display: flex;
    justify-content: center;
}

.title {
    font-size: 36rpx;
    color: #8f8f94;
}
</style>

7.接下来说一下容易出的错

image.png

上图所示就表示插件接入成功,如果提示6002的话可能是短时间内调用了两次或多次,

推送消息需要从极光后台进行推送,一般免费的广播所有人就能发10次,但可以用别名等方式发送,设置别名插件api上有,只有设置好别名才能进行推送,顺序不要反了,不然后台会报错,


image.png

发送信息有可能不在通知栏显示,这时候就要自己去设置手机app的权限了,允许通知后就可以在系统栏收到消息了,如果需要点击消息打开app也是一样道理,设置下系统权限就好

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容