ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
485 stars 562 forks source link

Push Notification no sound/vibration on IOs #1401

Closed AliuDardan closed 1 year ago

AliuDardan commented 1 year ago

Bug Report

Hi to all

I spent more than two days looking for a solution and came up empty-handed, so I'm hoping to find one here.

I have install

Plugin(s)

@capacitor/push-notifications

Capacitor Version

"@capacitor/push-notifications": "^4.1.2"
"@capacitor-community/fcm": "^3.0.2",
"@capacitor/android": "^4.0.0",
"@capacitor/app": "^4.0.0",
"@capacitor/core": "^4.0.0",
"@capacitor/device": "^4.0.1",
"@capacitor/haptics": "^4.0.0",
"@capacitor/ios": "^4.0.0",
"@capacitor/keyboard": "^4.0.0",
"@capacitor/status-bar": "^4.0.0",
"@directus/sdk": "^9.14.2",
"@ionic/vue": "^6.0.0",
"@ionic/vue-router": "^6.0.0",
"axios": "^0.26.1",
"chart.js": "^3.9.1",
"connect-history-api-fallback": "^2.0.0",
"core-js": "^3.6.5",
"express": "^4.17.3",
"pinia": "^2.0.14",
"vue": "^3.2.21",
"vue-axios": "^3.4.1",
"vue-chartjs": "^4.1.1",
"vue-i18n": "^9.1.0",
"vue-meta": "^3.0.0-alpha.4",
"vue-router": "^4.0.12"

Platform(s)

IOs

Current Behavior

When I received a notification from Firebase Console, the iPhone didn't make any sound or vibration. I also tried the Firebase Admin SDK, but got the same result. I received the notification as "Silent."

[log] - Push received: {"subtitle":"","data":{"google.c.a.ts":"1675261396","google.c.fid":"c-_IZqrBiEPrs2rV9Rm_B3","google.c.a.c_l":"Lineups test","google.c.a.udt":"0","gcm.n.e":"1","aps":{"alert":{"title":"test","body":"teat et wad sas d asd asdas"},"mutable-content":1},"google.c.sender.id":"589588543198","google.c.a.e":"1","gcm.message_id":"1675261396873814","google.c.a.c_id":"4213784315447060428"},"id":"21657EEC-9F6E-4E91-9A4E-214007EFBFB1","badge":1,"title":"test","body":"teat et wad sas d asd asdas"}

Expected Behavior

I expected that when the iPhone received a notification, it would at least use the default sound and vibrate.

Code Reproduction

The code for push notifications can be found here.

App.vue

 const initPushNotificationsPermission = async () => {
      await PushNotifications.requestPermissions().then(async result => {
        console.log('Request status: ' + JSON.stringify(result))
        if (result.receive === 'granted') {
          // Register with Apple / Google to receive push via APNS/FCM
          await PushNotifications.register();
          initNotifications();
        } else {
          // Show some error
          console.log('error token permissions');
        }
      });
    };
    const initNotifications = async () => {
      await PushNotifications.addListener('registration',
        async (token: Token) => {
          const firebaseToken = await FCM.getToken();
          console.log('Push registration success, token: ' + JSON.stringify(token));
          console.log('Token: ' + JSON.stringify(token.value));
          console.log('TokenFCM:: ' + JSON.stringify(firebaseToken));
        });

      PushNotifications.addListener('registrationError',
        (error: any) => {
          console.log('Error on registration: ' + JSON.stringify(error));
          // alert('Error on registration: ' + JSON.stringify(error));
        }
      );
      PushNotifications.addListener(
        'pushNotificationReceived',
        (notification: PushNotificationSchema) => {
          console.log('Push received: ' + JSON.stringify(notification));
          // alert(JSON.stringify(notification));
        },
      );

      PushNotifications.addListener(
        'pushNotificationActionPerformed',
        (notification: ActionPerformed) => {
          console.log('Push action performed: ' + JSON.stringify(notification));
          // alert(JSON.stringify(notification));
        },
      );
    }
**Podfile**
`require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'

platform :ios, '13.0'
use_frameworks!

# workaround to avoid Xcode caching of Pods that requires
# Product -> Clean Build Folder after new Cordova plugins installed
# Requires CocoaPods 1.6 or newer
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
  pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
  pod 'CapacitorCommunityFcm', :path => '../../node_modules/@capacitor-community/fcm'
  pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
  pod 'CapacitorDevice', :path => '../../node_modules/@capacitor/device'
  pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
  pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
  pod 'CapacitorPushNotifications', :path => '../../node_modules/@capacitor/push-notifications'
  pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
end

target 'App' do
  capacitor_pods
  # Add your Pods here
  pod 'Firebase/Messaging'

end

post_install do |installer|
  assertDeploymentTarget(installer)
end

AppDelegate.swift

import UIKit
import Capacitor
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        FirebaseApp.configure()
        return true
      }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        // Called when the app was launched with a url. Feel free to add additional processing here,
        // but if you want the App API to support tracking app url opens, make sure to keep this call
        return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
    }

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        // Called when the app was launched with an activity, including Universal Links.
        // Feel free to add additional processing here, but if you want the App API to support
        // tracking app url opens, make sure to keep this call
        return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
        Messaging.messaging().token(completion: { (token, error) in
        if let error = error {
            NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
        } else if let token = token {
            NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token)
        }
        })
    }

    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
    }

}

capacitor.config.json

{
    "appId": "*******",
    "appName": "TestApp",
    "webDir": "dist",
    "bundledWebRuntime": false,
    "plugins": {
        "PushNotifications": {
            "presentationOptions": [
                "badge",
                "sound",
                "alert"
            ]
        }
    }
}

capacitor.config.ts

/// <reference types="@capacitor/push-notifications" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: '*****',
  appName: 'TestApp',
  webDir: 'dist',
  bundledWebRuntime: false,
  plugins: {
    PushNotifications: {
      presentationOptions: ["badge", "sound", "alert"],
    },

  },
};

export default config;

Other Technical Details

Screen Shot 2023-02-01 at 16 17 43

IMG_0060

ionitron-bot[bot] commented 1 year ago

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.