zego_zpns 2.4.0+1 copy "zego_zpns: ^2.4.0+1" to clipboard
zego_zpns: ^2.4.0+1 copied to clipboard

ZEGO ZPNs Flutter SDK is a flutter plugin wrapper based on ZPNs native Android / iOS SDK.

example/lib/main.dart

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());
  CallKit.setInitConfiguration(CXProviderConfiguration(localizedName: 'localizedName',iconTemplateImageName: '211'));
  ZPNsEventHandler.onRegistered = (ZPNsRegisterMessage registerMessage) {
    log(registerMessage.errorCode.toString());
  };
  CallKitEventHandler.performAnswerCallAction = (CXAction action){
    log('answter');
    action.fulfill();
  };
  CallKitEventHandler.didReceiveIncomingPush = (Map extras, UUID uuid){
    log('didReceive');
  };
  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'),
        ),
      ),
    );
  }
}
3
likes
0
pub points
83%
popularity

Publisher

verified publisherzego.im

ZEGO ZPNs Flutter SDK is a flutter plugin wrapper based on ZPNs native Android / iOS SDK.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on zego_zpns