Skip to content

Commit

Permalink
[flutter_local_notifications] added Swift Package Manager support (#2500
Browse files Browse the repository at this point in the history
)

* added SPM support

* moved PrivacyInfo.xcprivacy

* updated Converters to avoid mixed language source file issue for SPM

* Swift Format

* fixed Swift Converters class

* change DarwinNotificationActionOption and DarwinNotificationCategoryOption to be enhanced enums

* Swift Format

---------

Co-authored-by: Anka <[email protected]>
Co-authored-by: Anka <[email protected]>
  • Loading branch information
3 people authored Dec 15, 2024
1 parent 5833dc8 commit 2f5215d
Show file tree
Hide file tree
Showing 26 changed files with 125 additions and 48 deletions.
5 changes: 5 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [19.0.0-dev.3]

* [iOS][macOS] **Breaking changes** the `DarwinNotificationActionOption` and `DarwinNotificationCategoryOption` are now enhanced enums with values accessible through the `value` property that are exactly the same as their native representations. Previously a bitwise left shift operation was applied to the index value
* [iOS][macOS] added Swift Package Manager support

## [19.0.0-dev.2]

* [Windows] Fixed an issue that happens with MSIX app builds. Thanks to PR from [Levi Lesches](https://github.com/Levi-Lesches)
Expand Down
Empty file.
1 change: 0 additions & 1 deletion flutter_local_notifications/ios/Classes/Converters.h

This file was deleted.

1 change: 0 additions & 1 deletion flutter_local_notifications/ios/Classes/Converters.m

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Flutter plugin for displaying local notifications.
DESC
s.homepage = 'https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications'
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Michael Bui' => '[email protected]' }
s.author = { 'Michael Bui' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.source_files = 'flutter_local_notifications/Sources/flutter_local_notifications/**/*.{h,m}'
s.public_header_files = 'flutter_local_notifications/Sources/flutter_local_notifications/include/**/*.h'
s.dependency 'Flutter'
s.resource_bundles = {'flutter_local_notifications_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
s.resource_bundles = {'flutter_local_notifications_privacy' => ['flutter_local_notifications/Sources/flutter_local_notifications/PrivacyInfo.xcprivacy']}
s.ios.deployment_target = '11.0'
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "flutter_local_notifications",
platforms: [
.iOS("11.0")
],
products: [
.library(name: "flutter-local-notifications", targets: ["flutter_local_notifications"])
],
dependencies: [],
targets: [
.target(
name: "flutter_local_notifications",
dependencies: [],
resources: [
.process("PrivacyInfo.xcprivacy")
],
cSettings: [
.headerSearchPath("include/flutter_local_notifications")
]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Sebastian Roth on 11/1/20.
//

#import "ActionEventSink.h"
#import "./include/flutter_local_notifications/ActionEventSink.h"

@interface ActionEventSink () {
NSMutableArray<NSDictionary *> *cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#import <Flutter/Flutter.h>

#import "ActionEventSink.h"
#import "FlutterEngineManager.h"
#import "./include/flutter_local_notifications/ActionEventSink.h"
#import "./include/flutter_local_notifications/FlutterEngineManager.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import "FlutterLocalNotificationsPlugin.h"
#import "ActionEventSink.h"
#import "Converters.h"
#import "FlutterEngineManager.h"
#import "./include/flutter_local_notifications/FlutterLocalNotificationsPlugin.h"
#import "./include/flutter_local_notifications/ActionEventSink.h"
#import "./include/flutter_local_notifications/Converters.h"
#import "./include/flutter_local_notifications/FlutterEngineManager.h"

@implementation FlutterLocalNotificationsPlugin {
FlutterMethodChannel *_channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension DarwinNotificationActionMapper on DarwinNotificationAction {
'identifier': identifier,
'title': title,
'options': options
.map((e) => 1 << e.index) // ignore: always_specify_types
.map((e) => e.value) // ignore: always_specify_types
.toList(),
'type': type.name,
if (buttonTitle != null) 'buttonTitle': buttonTitle!,
Expand All @@ -26,7 +26,7 @@ extension DarwinNotificationCategoryMapper on DarwinNotificationCategory {
.map((e) => e.toMap()) // ignore: always_specify_types
.toList(),
'options': options
.map((e) => 1 << e.index) // ignore: always_specify_types
.map((e) => e.value) // ignore: always_specify_types
.toList(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ enum DarwinNotificationActionOption {
/// The action can be performed only on an unlocked device.
///
/// Corresponds to [`UNNotificationActionOptions.authenticationRequired`](https://developer.apple.com/documentation/usernotifications/unnotificationactionoptions/1648196-authenticationrequired).
authenticationRequired,
authenticationRequired(1 << 0),

/// The action performs a destructive task.
///
/// Corresponds to [`UNNotificationActionOptions.destructive`](https://developer.apple.com/documentation/usernotifications/unnotificationactionoptions/1648199-destructive)
destructive,
destructive(1 << 1),

/// The action causes the app to launch in the foreground.
///
/// Corresponds to [`UNNotificationActionOptions.foreground`](https://developer.apple.com/documentation/usernotifications/unnotificationactionoptions/1648192-foreground)
foreground,
foreground(1 << 2);

/// Constructs an instance of [DarwinNotificationActionOption].
const DarwinNotificationActionOption(this.value);

/// The integer representation of [DarwinNotificationActionOption].
final int value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,34 @@ enum DarwinNotificationCategoryOption {
/// handling.
///
/// Corresponds to [`UNNotificationCategoryOptions.customDismissAction`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/1649280-customdismissaction).
customDismissAction,
customDismissAction(1 << 0),

/// Allow CarPlay to display notifications of this type.
///
/// Corresponds to [`UNNotificationCategoryOptions.allowInCarPlay`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/1649281-allowincarplay).
allowInCarPlay,
allowInCarPlay(1 << 1),

/// Show the notification's title, even if the user has disabled notification
/// previews for the app.
///
/// Corresponds to [`UNNotificationCategoryOptions.hiddenPreviewShowTitle`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/2873735-hiddenpreviewsshowtitle).
hiddenPreviewShowTitle,
hiddenPreviewShowTitle(1 << 2),

/// Show the notification's subtitle, even if the user has disabled
/// notification previews for the app.
///
/// Corresponds to [`UNNotificationCategoryOptions.hiddenPreviewShowSubtitle`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/2873734-hiddenpreviewsshowsubtitle).
hiddenPreviewShowSubtitle,
hiddenPreviewShowSubtitle(1 << 3),

/// An option that grants Siri permission to read incoming messages out loud
/// when the user has a compatible audio output device connected.
///
/// Corresponds to [`UNNotificationCategoryOptions.allowAnnouncement`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/3240647-allowannouncement).
allowAnnouncement,
allowAnnouncement(1 << 4);

/// Constructs an instance of [DarwinNotificationCategoryOption].
const DarwinNotificationCategoryOption(this.value);

/// The integer representation of [DarwinNotificationCategoryOption].
final int value;
}
20 changes: 0 additions & 20 deletions flutter_local_notifications/macos/Classes/Converters.h

This file was deleted.

1 change: 0 additions & 1 deletion flutter_local_notifications/macos/Classes/Converters.m

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Flutter plugin for displaying local notifications.
DESC
s.homepage = 'https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications'
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Michael Bui' => '[email protected]' }
s.author = { 'Michael Bui' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.source_files = 'flutter_local_notifications/Sources/flutter_local_notifications/**/*.swift'
s.dependency 'FlutterMacOS'

s.platform = :osx, '10.14'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.resource_bundles = {'flutter_local_notifications_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
s.resource_bundles = {'flutter_local_notifications_privacy' => ['flutter_local_notifications/Sources/flutter_local_notifications/PrivacyInfo.xcprivacy']}
s.swift_version = '5.0'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "flutter_local_notifications",
platforms: [
.macOS("10.14")
],
products: [
.library(name: "flutter-local-notifications", targets: ["flutter_local_notifications"])
],
dependencies: [],
targets: [
.target(
name: "flutter_local_notifications",
dependencies: [],
resources: [
.process("PrivacyInfo.xcprivacy")
],
cSettings: [
.headerSearchPath("include/flutter_local_notifications")
]
)
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import UserNotifications

public class Converters {
public static func parseNotificationCategoryOptions(_ options: [Any]?) -> UNNotificationCategoryOptions {
var result: UInt = 0

for option in options ?? [] {
guard let option = option as? NSNumber else {
continue
}
result |= option.uintValue
}

return UNNotificationCategoryOptions(rawValue: result)
}

public static func parseNotificationActionOptions(_ options: [Any]?) -> UNNotificationActionOptions {
var result: UInt = 0

for option in options ?? [] {
guard let option = option as? NSNumber else {
continue
}
result |= option.uintValue
}

return UNNotificationActionOptions(rawValue: result)
}
}
2 changes: 1 addition & 1 deletion flutter_local_notifications/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flutter_local_notifications
description: A cross platform plugin for displaying and scheduling local
notifications for Flutter applications with the ability to customise for each
platform.
version: 19.0.0-dev.2
version: 19.0.0-dev.3
homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications
issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues

Expand Down

0 comments on commit 2f5215d

Please sign in to comment.