Skip to content

Latest commit

 

History

History
236 lines (175 loc) · 7.04 KB

PUSH_NOTIF.md

File metadata and controls

236 lines (175 loc) · 7.04 KB

Pitel Voip Push notification

Warning IOS only working on real device, not on simulator (Callkit framework not working on simulator)

Pitel Connect Flow

When user make call from Pitel Connect app, Pitel Server pushes a notification for all user login (who receives the call). When user "Accept" call, extension will re-register to receive call. Pitel Connect Flow

Image callkit

iOS(Alert) iOS(Lockscreen) iOS(full screen)
Android(Alert) - Audio Android(Lockscreen | Fullscreen) - Audio

Setup & Certificate

IOS

If you are making VoIP application than you definitely want to update your application in the background & terminate state as well as wake your application when any VoIP call is being received.

1. Create Apple Push Notification certificate.

push_img_10

2. Choose an App ID from the pop-up menu, then click Continue. push_img_9

3. Upload Certificate Signing Request → Continue push_img_8

Follow the instructions to create a certificate signing request.

  • Install certificate. Download the certificate and install it into the Keychain Access app(download .cer and double click to install).
  • Export the .p12 file and send it to Tel4vn (or using test) push_img_7

Setup Pushkit & Callkit

IOS

  • Open Xcode Project → Capabilities
  • In Tab Signing & Capabilities. Enable Push notifications & Background Modes

push_img_5

  • Create APNs key and upload in firebase project. In your apple developer account. apns_key
  • Upload APNs key to your firebase
    • Create new your IOS App in Firebase project. ios_app
    • Download file .p8 to upload to firebase download_apns_key
    • Select IOS app -> upload Apns key upload_key_firebase
    • Fill information in upload Apns key popup upload_key_firebase_popup
Installing your Firebase configuration file
  • Next you must add the file to the project using Xcode (adding manually via the filesystem won't link the file to the project). Using Xcode, open the project's ios/{projectName}.xcworkspace file. Right click Runner from the left-hand side project navigation within Xcode and select "Add files", as seen below: ios_google_service_1
  • Select the GoogleService-Info.plist file you downloaded, and ensure the "Copy items if needed" checkbox is enabled: ios_google_service_2

Android

Using FCM (Firebase Cloud Message) to handle push notification wake up app when app run on Background or Terminate

Warning Popup request permission only working with targetSdkVersion >= 33

  • Access link https://console.firebase.google.com/u/0/project/_/notification

  • Create your packageId for android app push_img_4

  • Download & copy file google_service.json -> replace file google_service.json in path: android/app/google_service.json

  • Go to Project Setting → Cloud Messaging → Enable Cloud Messaging API (Legacy) push_img_3

Note After complete all step Setup. Please send information to dev of Tel4vn in here

Installation (your project)

  • Install Packages
flutter pub add flutter_callkit_incoming
  • Add pubspec.yaml:
dependencies:
      flutter_callkit_incoming: any

Config your project

  • Android In android/app/src/main/AndroidManifest.xml
<manifest...>
     ...
     <!--
         Using for load image from internet
     -->
     <uses-permission android:name="android.permission.INTERNET"/>
 </manifest>
  • IOS In ios/Runner/Info.plist
<key>UIBackgroundModes</key>
<array>
    <string>processing</string>
    <string>remote-notification</string>
    <string>voip</string>
</array>

Replace your file ios/Runner/AppDelegate.swift with

https://github.com/tel4vn/pitel-ui-kit/blob/1.0.6/ios/Runner/AppDelegate.swift

Usage

  • Before handle Incoming call, you should import package in home screen
import "package:flutter_pitel_voip/flutter_pitel_voip.dart";
  • Initialize firebase
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await PushNotifAndroid.initFirebase(DefaultFirebaseOptions.currentPlatform); // add here

  runApp(MyApp());
}
  • Config firebase_options.dart. example.

  • Get device push token VoIP.

await PushVoipNotif.getDeviceToken();
  • Get fcm token.
await PushVoipNotif.getFcmToken();

How to test

push_img_2

  • Fill information and click Send to Test Push Notification

Note: Add .voip after your bundleId to send voip push notification

Example:

Your app bundleId: com.pitel.uikit.demo
Voip push Bundle Id: com.pitel.uikit.demo.voip
  • IOS

push_img_1

  • Android: using above app or test from Postman

cURL

curl --location 'https://fcm.googleapis.com/fcm/send' \
--header 'Content-Type: application/json' \
--header 'Authorization: key=${server_key}' \
--data '{
    "registration_ids": [${device_token}],
    "data":{
        "uuid": "call_id",
        "nameCaller": "Anh Quang",
        "avatar": "Anh Quang",
        "phoneNumber": "0341111111",
        "appName": "Pitel Connnect",
        "callType": "CALL"
    },
    "content_available": true,
    "priority": "high"
}'