IOS
hefeixia
2021-02-18 49f3c1374873f73dbde2983ca0fcf1fb10bfedbf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (c) 2020 WildFireChat. All rights reserved.
 */
 
package cn.wildfirechat.push;
 
import android.content.Context;
 
/**
 * Created by heavyrain.lee on 2018/3/18.
 */
 
public abstract class PushMessageHandler {
    /*
    如果需要自定义push的展示,请实现CUSTOM_PUSH_MSG_HANDLER类,并继承PushMessageHandler。构造函数为默认构造函数
     */
    public static final String CUSTOM_PUSH_MSG_HANDLER = "cn.wildfirechat.push.CustomPushMessageHandler";
 
    public static final int DEFAULT_NOTIFICATION_ID = 1883;
    public static final int DEFAULT_NOTIFICATION_CALL_ID = 1884;
    private static PushMessageHandler customHandler;
    private static PushMessageHandler defaultHandler;
 
    static {
        defaultHandler = new DefaultPushMessageHandler();
        try {
            Class cls = Class.forName(CUSTOM_PUSH_MSG_HANDLER);
            customHandler = (PushMessageHandler) cls.newInstance();
        } catch (ClassNotFoundException e) {
            //e.printStackTrace();
        } catch (InstantiationException e) {
            //e.printStackTrace();
        } catch (IllegalAccessException e) {
            //e.printStackTrace();
        }
    }
 
    //IM push message
    abstract public void handleIMPushMessage(Context context, AndroidPushMessage pushMessage, PushService.PushServiceType pushServiceType);
 
    //Application push data
    abstract public void handlePushMessageData(Context context, String pushData);
 
 
    public static void didReceiveIMPushMessage(final Context context, final AndroidPushMessage pushMessage, final PushService.PushServiceType pushServiceType) {
        if (customHandler != null) {
            customHandler.handleIMPushMessage(context, pushMessage, pushServiceType);
        } else if (defaultHandler != null) {
            defaultHandler.handleIMPushMessage(context, pushMessage, pushServiceType);
        }
    }
 
 
    public static void didReceivePushMessageData(Context context, String pushData) {
        if (customHandler != null) {
            customHandler.handlePushMessageData(context, pushData);
        } else if (defaultHandler != null) {
            defaultHandler.handlePushMessageData(context, pushData);
        }
    }
 
}