Skip to content

Commit 2f5215d

Browse files
MaikuBAnkaAnka
authored
[flutter_local_notifications] added Swift Package Manager support (#2500)
* 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]>
1 parent 5833dc8 commit 2f5215d

26 files changed

+125
-48
lines changed

flutter_local_notifications/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [19.0.0-dev.3]
2+
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
4+
* [iOS][macOS] added Swift Package Manager support
5+
16
## [19.0.0-dev.2]
27

38
* [Windows] Fixed an issue that happens with MSIX app builds. Thanks to PR from [Levi Lesches](https://github.com/Levi-Lesches)

flutter_local_notifications/ios/Assets/.gitkeep

Whitespace-only changes.

flutter_local_notifications/ios/Classes/Converters.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter_local_notifications/ios/Classes/Converters.m

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter_local_notifications/ios/flutter_local_notifications.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Flutter plugin for displaying local notifications.
1010
DESC
1111
s.homepage = 'https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications'
1212
s.license = { :type => 'BSD', :file => '../LICENSE' }
13-
s.author = { 'Michael Bui' => '[email protected]' }
13+
s.author = { 'Michael Bui' => '[email protected]' }
1414
s.source = { :path => '.' }
15-
s.source_files = 'Classes/**/*'
16-
s.public_header_files = 'Classes/**/*.h'
15+
s.source_files = 'flutter_local_notifications/Sources/flutter_local_notifications/**/*.{h,m}'
16+
s.public_header_files = 'flutter_local_notifications/Sources/flutter_local_notifications/include/**/*.h'
1717
s.dependency 'Flutter'
18-
s.resource_bundles = {'flutter_local_notifications_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
18+
s.resource_bundles = {'flutter_local_notifications_privacy' => ['flutter_local_notifications/Sources/flutter_local_notifications/PrivacyInfo.xcprivacy']}
1919
s.ios.deployment_target = '11.0'
2020
end
2121

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "flutter_local_notifications",
8+
platforms: [
9+
.iOS("11.0")
10+
],
11+
products: [
12+
.library(name: "flutter-local-notifications", targets: ["flutter_local_notifications"])
13+
],
14+
dependencies: [],
15+
targets: [
16+
.target(
17+
name: "flutter_local_notifications",
18+
dependencies: [],
19+
resources: [
20+
.process("PrivacyInfo.xcprivacy")
21+
],
22+
cSettings: [
23+
.headerSearchPath("include/flutter_local_notifications")
24+
]
25+
)
26+
]
27+
)

flutter_local_notifications/ios/Classes/ActionEventSink.m renamed to flutter_local_notifications/ios/flutter_local_notifications/Sources/flutter_local_notifications/ActionEventSink.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Created by Sebastian Roth on 11/1/20.
66
//
77

8-
#import "ActionEventSink.h"
8+
#import "./include/flutter_local_notifications/ActionEventSink.h"
99

1010
@interface ActionEventSink () {
1111
NSMutableArray<NSDictionary *> *cache;

flutter_local_notifications/ios/Classes/FlutterEngineManager.m renamed to flutter_local_notifications/ios/flutter_local_notifications/Sources/flutter_local_notifications/FlutterEngineManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#import <Flutter/Flutter.h>
1111

12-
#import "ActionEventSink.h"
13-
#import "FlutterEngineManager.h"
12+
#import "./include/flutter_local_notifications/ActionEventSink.h"
13+
#import "./include/flutter_local_notifications/FlutterEngineManager.h"
1414

1515
NS_ASSUME_NONNULL_BEGIN
1616

flutter_local_notifications/ios/Classes/FlutterLocalNotificationsPlugin.m renamed to flutter_local_notifications/ios/flutter_local_notifications/Sources/flutter_local_notifications/FlutterLocalNotificationsPlugin.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#import "FlutterLocalNotificationsPlugin.h"
2-
#import "ActionEventSink.h"
3-
#import "Converters.h"
4-
#import "FlutterEngineManager.h"
1+
#import "./include/flutter_local_notifications/FlutterLocalNotificationsPlugin.h"
2+
#import "./include/flutter_local_notifications/ActionEventSink.h"
3+
#import "./include/flutter_local_notifications/Converters.h"
4+
#import "./include/flutter_local_notifications/FlutterEngineManager.h"
55

66
@implementation FlutterLocalNotificationsPlugin {
77
FlutterMethodChannel *_channel;

flutter_local_notifications/lib/src/platform_specifics/darwin/mappers.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension DarwinNotificationActionMapper on DarwinNotificationAction {
1111
'identifier': identifier,
1212
'title': title,
1313
'options': options
14-
.map((e) => 1 << e.index) // ignore: always_specify_types
14+
.map((e) => e.value) // ignore: always_specify_types
1515
.toList(),
1616
'type': type.name,
1717
if (buttonTitle != null) 'buttonTitle': buttonTitle!,
@@ -26,7 +26,7 @@ extension DarwinNotificationCategoryMapper on DarwinNotificationCategory {
2626
.map((e) => e.toMap()) // ignore: always_specify_types
2727
.toList(),
2828
'options': options
29-
.map((e) => 1 << e.index) // ignore: always_specify_types
29+
.map((e) => e.value) // ignore: always_specify_types
3030
.toList(),
3131
};
3232
}

flutter_local_notifications/lib/src/platform_specifics/darwin/notification_action_option.dart

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ enum DarwinNotificationActionOption {
77
/// The action can be performed only on an unlocked device.
88
///
99
/// Corresponds to [`UNNotificationActionOptions.authenticationRequired`](https://developer.apple.com/documentation/usernotifications/unnotificationactionoptions/1648196-authenticationrequired).
10-
authenticationRequired,
10+
authenticationRequired(1 << 0),
1111

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

1717
/// The action causes the app to launch in the foreground.
1818
///
1919
/// Corresponds to [`UNNotificationActionOptions.foreground`](https://developer.apple.com/documentation/usernotifications/unnotificationactionoptions/1648192-foreground)
2020
21-
foreground,
21+
foreground(1 << 2);
22+
23+
/// Constructs an instance of [DarwinNotificationActionOption].
24+
const DarwinNotificationActionOption(this.value);
25+
26+
/// The integer representation of [DarwinNotificationActionOption].
27+
final int value;
2228
}

flutter_local_notifications/lib/src/platform_specifics/darwin/notification_category_option.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@ enum DarwinNotificationCategoryOption {
77
/// handling.
88
///
99
/// Corresponds to [`UNNotificationCategoryOptions.customDismissAction`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/1649280-customdismissaction).
10-
customDismissAction,
10+
customDismissAction(1 << 0),
1111

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

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

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

2929
/// An option that grants Siri permission to read incoming messages out loud
3030
/// when the user has a compatible audio output device connected.
3131
///
3232
/// Corresponds to [`UNNotificationCategoryOptions.allowAnnouncement`](https://developer.apple.com/documentation/usernotifications/unnotificationcategoryoptions/3240647-allowannouncement).
33-
allowAnnouncement,
33+
allowAnnouncement(1 << 4);
34+
35+
/// Constructs an instance of [DarwinNotificationCategoryOption].
36+
const DarwinNotificationCategoryOption(this.value);
37+
38+
/// The integer representation of [DarwinNotificationCategoryOption].
39+
final int value;
3440
}

flutter_local_notifications/macos/Classes/Converters.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

flutter_local_notifications/macos/Classes/Converters.m

Lines changed: 0 additions & 1 deletion
This file was deleted.

flutter_local_notifications/macos/flutter_local_notifications.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Flutter plugin for displaying local notifications.
1111
DESC
1212
s.homepage = 'https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications'
1313
s.license = { :type => 'BSD', :file => '../LICENSE' }
14-
s.author = { 'Michael Bui' => '[email protected]' }
14+
s.author = { 'Michael Bui' => '[email protected]' }
1515
s.source = { :path => '.' }
16-
s.source_files = 'Classes/**/*'
16+
s.source_files = 'flutter_local_notifications/Sources/flutter_local_notifications/**/*.swift'
1717
s.dependency 'FlutterMacOS'
1818

1919
s.platform = :osx, '10.14'
2020
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
21-
s.resource_bundles = {'flutter_local_notifications_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
21+
s.resource_bundles = {'flutter_local_notifications_privacy' => ['flutter_local_notifications/Sources/flutter_local_notifications/PrivacyInfo.xcprivacy']}
2222
s.swift_version = '5.0'
2323
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "flutter_local_notifications",
8+
platforms: [
9+
.macOS("10.14")
10+
],
11+
products: [
12+
.library(name: "flutter-local-notifications", targets: ["flutter_local_notifications"])
13+
],
14+
dependencies: [],
15+
targets: [
16+
.target(
17+
name: "flutter_local_notifications",
18+
dependencies: [],
19+
resources: [
20+
.process("PrivacyInfo.xcprivacy")
21+
],
22+
cSettings: [
23+
.headerSearchPath("include/flutter_local_notifications")
24+
]
25+
)
26+
]
27+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import UserNotifications
2+
3+
public class Converters {
4+
public static func parseNotificationCategoryOptions(_ options: [Any]?) -> UNNotificationCategoryOptions {
5+
var result: UInt = 0
6+
7+
for option in options ?? [] {
8+
guard let option = option as? NSNumber else {
9+
continue
10+
}
11+
result |= option.uintValue
12+
}
13+
14+
return UNNotificationCategoryOptions(rawValue: result)
15+
}
16+
17+
public static func parseNotificationActionOptions(_ options: [Any]?) -> UNNotificationActionOptions {
18+
var result: UInt = 0
19+
20+
for option in options ?? [] {
21+
guard let option = option as? NSNumber else {
22+
continue
23+
}
24+
result |= option.uintValue
25+
}
26+
27+
return UNNotificationActionOptions(rawValue: result)
28+
}
29+
}

flutter_local_notifications/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flutter_local_notifications
22
description: A cross platform plugin for displaying and scheduling local
33
notifications for Flutter applications with the ability to customise for each
44
platform.
5-
version: 19.0.0-dev.2
5+
version: 19.0.0-dev.3
66
homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications
77
issue_tracker: https://github.com/MaikuB/flutter_local_notifications/issues
88

0 commit comments

Comments
 (0)