ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web โšก๏ธ
https://capacitorjs.com
MIT License
12.11k stars 1k forks source link

bug: userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: not called #4920

Closed rafus15 closed 3 years ago

rafus15 commented 3 years ago

Bug Report

Capacitor Version

๐Ÿ’Š Capacitor Doctor ๐Ÿ’Š

Latest Dependencies:

@capacitor/cli: 3.1.2 @capacitor/core: 3.1.2 @capacitor/android: 3.1.2 @capacitor/ios: 3.1.2

Installed Dependencies:

@capacitor/android: not installed @capacitor/core: 3.1.2 @capacitor/cli: 3.1.2 @capacitor/ios: 3.1.2

[success] iOS looking great! ๐Ÿ‘Œ

Platform(s)

*iOS

Current Behavior

UNUserNotificationCenter, didReceive response: not being called when a user performs a notification action

Expected Behavior

Prior to Version 3 releasing i was using this delegate call to perform actions in background when user selected a notification action

Code Reproduction

import UIKit import Capacitor import CoreLocation

@available(iOS 14.0, *) @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate, UNUserNotificationCenterDelegate {

var window: UIWindow? let locationManager = CLLocationManager()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.announcement,.badge,.sound,.carPlay,.criticalAlert,.provisional], completionHandler: { (granted, error) in
       if granted {
           // Register after we get the permissions.
           UNUserNotificationCenter.current().delegate = self
       }
   })
let notificationCenter = UNUserNotificationCenter.current()
notificationCenter.delegate = self;

// Define the custom actions.
let acceptAction = UNNotificationAction(identifier: "OPEN_DOOR",
      title: "Abrir el portal",
      options: UNNotificationActionOptions(rawValue: 0))

// Define the notification type
let meetingInviteCategory =
      UNNotificationCategory(identifier: "OPEN_DOOR_CATEGORY",
      actions: [acceptAction, ],
      intentIdentifiers: [],
      hiddenPreviewsBodyPlaceholder: "",
      options: .customDismissAction)
// Register the notification type.
notificationCenter.setNotificationCategories([meetingInviteCategory])

// Override point for customization after application launch.
locationManager.delegate = self
 // 2
print("location manager got!");
 locationManager.requestAlwaysAuthorization()

return true

} func locationManager( manager: CLLocationManager, didFailWithError error: Error) { print("Location ERROR") print(error); } func locationManager( manager: CLLocationManager, didEnterRegion region: CLRegion) { print("enter region!!");

        let body = "Parece que estรกs llegando a casa"
        let notificationContent = UNMutableNotificationContent()

        notificationContent.body = body
        notificationContent.sound = .default
    notificationContent.categoryIdentifier = "OPEN_DOOR_CATEGORY"
        let trigger = UNTimeIntervalNotificationTrigger(
        timeInterval: 1,
          repeats: false)
        let request = UNNotificationRequest(

          identifier: "location_change",
          content: notificationContent,

          trigger: trigger)
        UNUserNotificationCenter.current().add(request) { error in
          if let error = error {
            print("Error: \(error)")
          }
        }
    print("suuccess publishing notification")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
    print("exit region!!");
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {

  // 1
  let status = locationManager.authorizationStatus
    print("location upgrade!");
    print(status);
  // 2
  //mapView.showsUserLocation = (status == .authorizedAlways)

  // 3
  if status != .authorizedAlways {
    let message = """
    Your geotification is saved but will only be activated once you grant
    Geotify permission to access the device location.
    """
    print(message);
    //showAlert(withTitle: "Warning", message: message)
  }else{
    let reg = CLCircularRegion(center: CLLocationCoordinate2D(latitude: 00.001488, longitude: 0.040547), radius: 120, identifier: "casa");
    locationManager.startMonitoring(for: reg);
  }
}

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) { UIApplication.shared.applicationIconBadgeNumber = 0 // 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 userNotificationCenter( center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { print("RAFA--->>>>>>>") completionHandler([.alert,.sound]) //do sth }

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

    print("RECV!!!!");
    print(response.actionIdentifier);
}

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) }

override func touchesBegan(_ touches: Set, with event: UIEvent?) { super.touchesBegan(touches, with: event)

let statusBarRect = UIApplication.shared.statusBarFrame
guard let touchPoint = event?.allTouches?.first?.location(in: self.window) else { return }

if statusBarRect.contains(touchPoint) {
     NotificationCenter.default.post(name: .capacitorStatusBarTapped, object: nil)
}

}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: deviceToken)

}

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

}

}

Ionitron commented 3 years ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron ๐Ÿ’™

Ionitron commented 3 years ago

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day! Ionitron ๐Ÿ’™

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 Capacitor, please create a new issue and ensure the template is fully filled out.