diff --git a/.changeset/lucky-otters-listen.md b/.changeset/lucky-otters-listen.md new file mode 100644 index 00000000..0c6cb2e8 --- /dev/null +++ b/.changeset/lucky-otters-listen.md @@ -0,0 +1,5 @@ +--- +"@capacitor/background-runner": minor +--- + +(iOS): Fixes the iOS 14 and iOS 15 deprecation warnings in the geolocation and notifications APIs. The deprecated `CLLocationManager.authorizationStatus()` class method is replaced by the `authorizationStatus` instance property, and `summaryArgument` is no longer set on scheduled notifications because iOS ignores it since iOS 15. The `summaryArgument` notification option is deprecated and now has no effect. diff --git a/packages/capacitor-plugin/API.md b/packages/capacitor-plugin/API.md index f3d80942..69d6ded0 100644 --- a/packages/capacitor-plugin/API.md +++ b/packages/capacitor-plugin/API.md @@ -64,7 +64,7 @@ Send basic local notifications. | **`sound`** | string | Name of the audio file to play when this notification is displayed. Include the file extension with the filename. On iOS, the file should be in the app bundle. On Android, the file should be in res/raw folder. Recommended format is `.wav` because is supported by both iOS and Android. Only available for iOS and Android < 26. For Android 26+ use channelId of a channel configured with the desired sound. If the sound file is not found, (i.e. empty string or wrong name) the default system notification sound will be used. If not provided, it will produce the default sound on Android and no sound on iOS. | 1.0.0 | | **`actionTypeId`** | string | Associate an action type with this notification. | 1.0.0 | | **`threadIdentifier`** | string | Used to group multiple notifications. Sets `threadIdentifier` on the [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). Only available for iOS. | 1.0.0 | -| **`summaryArgument`** | string | The string this notification adds to the category's summary format string. Sets `summaryArgument` on the [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). Only available for iOS. | 1.0.0 | +| **`summaryArgument`** | string | The string this notification adds to the category's summary format string. Only available for iOS. **This option has no effect.** `summaryArgument` on [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent) is deprecated since iOS 15 and the value is ignored by the system, so it is no longer set on the notification content. | 1.0.0 | | **`group`** | string | Used to group multiple notifications. Calls `setGroup()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android. | 1.0.0 | | **`groupSummary`** | string | If true, this notification becomes the summary for a group of notifications. Calls `setGroupSummary()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android when using `group`. | 1.0.0 | | **`extra`** | any | Set extra data to store within this notification. | 1.0.0 | diff --git a/packages/capacitor-plugin/README.md b/packages/capacitor-plugin/README.md index a1dbe5e9..9367938b 100644 --- a/packages/capacitor-plugin/README.md +++ b/packages/capacitor-plugin/README.md @@ -521,7 +521,7 @@ Send basic local notifications. | **`sound`** | string | Name of the audio file to play when this notification is displayed. Include the file extension with the filename. On iOS, the file should be in the app bundle. On Android, the file should be in res/raw folder. Recommended format is `.wav` because is supported by both iOS and Android. Only available for iOS and Android < 26. For Android 26+ use channelId of a channel configured with the desired sound. If the sound file is not found, (i.e. empty string or wrong name) the default system notification sound will be used. If not provided, it will produce the default sound on Android and no sound on iOS. | 1.0.0 | | **`actionTypeId`** | string | Associate an action type with this notification. | 1.0.0 | | **`threadIdentifier`** | string | Used to group multiple notifications. Sets `threadIdentifier` on the [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). Only available for iOS. | 1.0.0 | -| **`summaryArgument`** | string | The string this notification adds to the category's summary format string. Sets `summaryArgument` on the [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). Only available for iOS. | 1.0.0 | +| **`summaryArgument`** | string | The string this notification adds to the category's summary format string. Only available for iOS. **This option has no effect.** `summaryArgument` on [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent) is deprecated since iOS 15 and the value is ignored by the system, so it is no longer set on the notification content. | 1.0.0 | | **`group`** | string | Used to group multiple notifications. Calls `setGroup()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android. | 1.0.0 | | **`groupSummary`** | string | If true, this notification becomes the summary for a group of notifications. Calls `setGroupSummary()` on [`NotificationCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder) with the provided value. Only available for Android when using `group`. | 1.0.0 | | **`extra`** | any | Set extra data to store within this notification. | 1.0.0 | diff --git a/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Geolocation.swift b/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Geolocation.swift index 0a5c82da..ff848d7f 100644 --- a/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Geolocation.swift +++ b/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Geolocation.swift @@ -18,6 +18,8 @@ enum CapacitorGeolocationErrors: Error, Equatable { } class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationManagerDelegate { + private static let permissionManager = CLLocationManager() + private weak var context: Context? private var pendingCurrentLocationCalls: [Int: (Result) -> Void] = [:] private var isWatchingLocation: Bool = false @@ -36,7 +38,7 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan self.context = context self.locationManager.delegate = self - if CLLocationManager.authorizationStatus() == .authorizedAlways { + if self.locationManager.authorizationStatus == .authorizedAlways { self.locationManager.allowsBackgroundLocationUpdates = true self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer self.locationManager.pausesLocationUpdatesAutomatically = false @@ -55,8 +57,8 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan var permission: String = "prompt" - switch CLLocationManager.authorizationStatus() { - case .authorized, .authorizedWhenInUse, .authorizedAlways: + switch permissionManager.authorizationStatus { + case .authorizedWhenInUse, .authorizedAlways: permission = "granted" case .notDetermined: permission = "prompt" @@ -74,7 +76,7 @@ class CapacitorGeolocation: NSObject, CapacitorGeolocationExports, CLLocationMan return } - if CLLocationManager.authorizationStatus() != .notDetermined { + if self.locationManager.authorizationStatus != .notDetermined { return } diff --git a/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Notifications.swift b/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Notifications.swift index 1e33243e..f611994a 100644 --- a/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Notifications.swift +++ b/packages/capacitor-plugin/ios/Sources/CapacitorBackgroundRunner/CapacitorAPI/Notifications.swift @@ -30,8 +30,6 @@ struct NotificationOption { let actionTypeId: String? let extra: [String: Any]? let threadIdentifier: String? - let summaryArgument: String? - let groupSummary: String? init(from dict: [String: Any?]) throws { guard let id = dict["id"] as? Int else { @@ -58,8 +56,6 @@ struct NotificationOption { self.sound = dict["sound"] as? String self.actionTypeId = dict["actionTypeId"] as? String self.extra = dict["extra"] as? [String: Any] - self.summaryArgument = dict["summaryArgument"] as? String - self.groupSummary = dict["groupSummary"] as? String } } @@ -151,10 +147,6 @@ class CapacitorNotifications: NSObject, CapacitorNotificationsExports { content.threadIdentifier = threadIdentifier } - if let summaryArgument = notificationOption.summaryArgument { - content.summaryArgument = summaryArgument - } - if let sound = notificationOption.sound { content.sound = UNNotificationSound(named: UNNotificationSoundName(sound)) } diff --git a/packages/capacitor-plugin/src/apis.ts b/packages/capacitor-plugin/src/apis.ts index 132eabb7..d17ef8bd 100644 --- a/packages/capacitor-plugin/src/apis.ts +++ b/packages/capacitor-plugin/src/apis.ts @@ -147,12 +147,15 @@ export interface NotificationScheduleOptions { /** * The string this notification adds to the category's summary format string. * - * Sets `summaryArgument` on the - * [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent). - * * Only available for iOS. * + * **This option has no effect.** `summaryArgument` on + * [`UNMutableNotificationContent`](https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent) + * is deprecated since iOS 15 and the value is ignored by the system, so it is + * no longer set on the notification content. + * * @since 1.0.0 + * @deprecated This option has no effect, iOS ignores it since iOS 15. */ summaryArgument?: string; /**