zego_zpns 2.3.2 zego_zpns: ^2.3.2 copied to clipboard
ZEGO ZPNs Flutter SDK is a flutter plugin wrapper based on ZPNs native Android / iOS SDK.
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:zego_zpns/zego_zpns.dart';
@pragma('vm:entry-point')
Future<void> _zpnsMessagingBackgroundHandler(ZPNsMessage message) async{
print("good job");
}
void main() async {
runApp(const MyApp());
ZPNsEventHandler.onRegistered = (ZPNsRegisterMessage registerMessage) {
log(registerMessage.errorCode.toString());
};
ZPNs.setBackgroundMessageHandler(_zpnsMessagingBackgroundHandler);
ZPNsConfig config = ZPNsConfig();
config.enableFCMPush = true;
ZPNs.setPushConfig(config);
// Request notification rights from the user when appropriate,iOS only
ZPNs.getInstance().applyNotificationPermission();
// Select an ZPNsIOSEnvironment value based on the iOS development/Distribution certificate.Change this enum when switching certificates
ZPNs.getInstance()
.registerPush(iOSEnvironment: ZPNsIOSEnvironment.Development,enableIOSVoIP: true)
.catchError((onError) {
if (onError is PlatformException) {
//Notice exception here
log(onError.message ?? "");
}
});
ZPNsEventHandler.onNotificationClicked = (ZPNsMessage zpnsMessage) {
if (zpnsMessage.pushSourceType == ZPNsPushSourceType.APNs) {
Map aps = Map.from(zpnsMessage.extras['aps'] as Map);
String payload = aps['payload'];
log("My payload is $payload");
} else if (zpnsMessage.pushSourceType == ZPNsPushSourceType.FCM) {
// FCM does not support this interface,please use Intent get payload at Android Activity.
}
log("user clicked the offline push notification,title is ${zpnsMessage.title},content is ${zpnsMessage.content}");
};
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const Center(
child: Text('ZPNs Sample'),
),
),
);
}
}