package com.wisewoods.eduandroid.app;


import android.content.Context;
import android.util.Log;

import com.pgyer.pgyersdk.PgyerSDKManager;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.wisewoods.base.app.BaseApp;

public class App extends BaseApp {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //在attachBaseContext方法中调用初始化sdk
        initPgyerSDK(this);
    }

    /**
     * 初始化蒲公英SDK
     */
    private static void initPgyerSDK(App application) {
        new PgyerSDKManager.Init()
                .setContext(application) //设置上下问对象
                .start();
    }

    @Override
    public void onCreate() {
        super.onCreate();

        //注册推送
        initPush();
    }

    private void initPush() {
        XGPushConfig.enableDebug(this, true);

        XGPushManager.registerPush(this, new XGIOperateCallback() {
            @Override
            public void onSuccess(Object data, int flag) {
                //token在设备卸载重装的时候有可能会变
                Log.d("TPush", "注册成功，设备token为：" + data);
            }

            @Override
            public void onFail(Object data, int errCode, String msg) {
                Log.d("TPush", "注册失败，错误码：" + errCode + ",错误信息：" + msg);
            }
        });
    }


}
