友盟推送是一款完全免费的app推送,推送可以提升用户粘性,提高App活跃度。示例实现了:单设备推送,列表推送,组播推送,文件推送,自定义推送,广播推送,ios支持主标题副标题,对推送进行日志拦截,支持小米推送。

整体项目

imagepng

pom配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.1.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.cimu</groupId>
	<artifactId>chapter_umeng</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>chapter_umeng</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.json</groupId>
			<artifactId>json</artifactId>
			<version>20140107</version>
		</dependency>
		<dependency>
			<groupId>com.squareup.okhttp3</groupId>
			<artifactId>okhttp</artifactId>
			<version>3.8.0</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.30</version>
		</dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.2</version>
        </dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>

核心代码

com.cimu.umeng.android包下为android推送类型类。
com.cimu.umeng.ios包下为ios推送类型类。
xxBroadcast:广播类;
xxCustomizedcast:自定义广播类;
xxFilecast:文件播;
xxGroupcast:组播类;
xxListcast:列播类;
xxUnicast:单播类;

UmengNotification:推送处理抽象类;
AndroidNotification:android推送处理类,继承UmengNotification;
IOSNotification:ios推送处理类,继承UmengNotification;
PushClient:推送请求类,真正发http请求的类;

ApiResult:调用接口返回结果;
ApiResultData:返回具体数据;
Demo:实现各个方法的调用;

HttpLogInterceptor:http日志拦截;

源码地址

本文为博主原创文章,未经博主允许不得转载。
更多内容请访问:IT源点

注意:本文归作者所有,未经作者允许,不得转载