ionic2、3调用[极光IM] jmessage-ionic2

jmessage-chenyu 

Jmessage Native

为极光IM即时通讯写的ionic2、3写的调用方式

安装

 
   
安装插件
cordova plugin add jmessage-phonegap-plugin --variable APP_KEY=your_app_key
安装ionic2、3调用
npm install jmessage-chenyu --save

官方文档

For the full Ionic Native documentation, please visit https://ionicframework.com/docs/native/.

调用

需要把包装类注入到 @NgModuleproviders 中,然后调用

 
   
// app.module.ts
import {JmessageChenyu} from "jmessage-chenyu";
...
 
@NgModule({
  ...
 
  providers[
    ...
    JmessageChenyu
    ...
  ]
  ...
})
export class AppModule { }
 
   
import {JmessageChenyu} from "jmessage-chenyu";
import { Platform } from 'ionic-angular';
 
import { NgZone } from '@angular/core';
 
@Component({ ... })
export class MyComponent {
 
  constructor(private jMessageChenyu: JmessageChenyu, private platform: Platform) {
 
    platform.ready().then(() => {
 
      // 初始化插件
      this.jMessageChenyu.init({ isOpenMessageRoaming: true })
      //用户注册。
      let obj ={username: id, password: '123456'}
      //obj对应的参数详情请看文档
      //https://github.com/jpush/jmessage-phonegap-plugin/wiki/APIs
      this.jMessageChenyu.register(obj)
            .then(() => {
              this.toast("注册成功,请登录!")
            })
            .catch((error) => {
              this.toast("注册失败" + JSON.stringify(error))
            });
      //用户登录
      this.jMessageChenyu.login(obj).then(
          //代码
       )
      this.jMessageChenyu.logout().then(
            //代码
      )
      //获取用户信息
      this.jMessageChenyu.getMyInfo().then()
      // 此处省略很多方法... 详情对照https://github.com/jpush/jmessage-phonegap-plugin/wiki/APIs 方法名
 
 
    });
    
  }
  
}
 
发布了45 篇原创文章 · 获赞 22 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_24542767/article/details/79428938