Skip to content

Commit cde241f

Browse files
mvanbeusekomened
andauthored
Background refresh status platform specific implementations (#1282)
* Fix/1174 background refresh status (#1176) * Update project files * Add a new background refresh permission check for iOS * versions * cleanups * version bumps * missing constants * Revert to platforms to main --------- Co-authored-by: Sebastian Roth <sebastian.roth@gmail.com>
1 parent c013888 commit cde241f

File tree

11 files changed

+72
-6
lines changed

11 files changed

+72
-6
lines changed

permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ final class PermissionConstants {
6161
static final int PERMISSION_GROUP_CALENDAR_WRITE_ONLY = 36;
6262
static final int PERMISSION_GROUP_CALENDAR_FULL_ACCESS = 37;
6363
static final int PERMISSION_GROUP_ASSISTANT = 38;
64+
static final int PERMISSION_GROUP_BACKGROUND_REFRESH = 39;
6465

6566
@Retention(RetentionPolicy.SOURCE)
6667
@IntDef({

permission_handler_android/example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> {
4242
permission != Permission.bluetooth &&
4343
permission != Permission.appTrackingTransparency &&
4444
permission != Permission.criticalAlerts &&
45-
permission != Permission.assistant;
45+
permission != Permission.assistant &&
46+
permission != Permission.backgroundRefresh;
4647
})
4748
.map((permission) => PermissionWidget(permission))
4849
.toList()),

permission_handler_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ flutter:
1818
dependencies:
1919
flutter:
2020
sdk: flutter
21-
permission_handler_platform_interface: ^4.1.0
21+
permission_handler_platform_interface: ^4.2.0
2222

2323
dev_dependencies:
2424
flutter_lints: ^1.0.4

permission_handler_apple/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 9.4.0
2+
3+
* Adds a new permission `Permission.backgroundRefresh` to check the background refresh permission status.
4+
15
## 9.3.1
26

37
* Updates plist key from `NSPhotoLibraryUsageDescription` to `NSPhotoLibraryAddUsageDescription`.

permission_handler_apple/ios/Classes/PermissionHandlerEnums.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ typedef NS_ENUM(int, PermissionGroup) {
162162
PermissionGroupSensorsAlways,
163163
PermissionGroupCalendarWriteOnly,
164164
PermissionGroupCalendarFullAccess,
165-
PermissionGroupAssistant
165+
PermissionGroupAssistant,
166+
PermissionGroupBackgroundRefresh
166167
};
167168

168169
typedef NS_ENUM(int, PermissionStatus) {

permission_handler_apple/ios/Classes/PermissionManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#import "AudioVideoPermissionStrategy.h"
1313
#import "AppTrackingTransparencyPermissionStrategy.h"
14+
#import "BackgroundRefreshStrategy.h"
1415
#import "BluetoothPermissionStrategy.h"
1516
#import "ContactPermissionStrategy.h"
1617
#import "EventPermissionStrategy.h"

permission_handler_apple/ios/Classes/PermissionManager.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ + (id)createPermissionStrategy:(PermissionGroup)permission {
149149
return [CriticalAlertsPermissionStrategy new];
150150
case PermissionGroupAssistant:
151151
return [AssistantPermissionStrategy new];
152+
case PermissionGroupBackgroundRefresh:
153+
return [BackgroundRefreshStrategy new];
152154
default:
153155
return [UnknownPermissionStrategy new];
154156
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// BackgroundRefreshStrategy.h
3+
// permission_handler_apple
4+
//
5+
// Created by Sebastian Roth on 28/09/2023.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
#import "PermissionStrategy.h"
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface BackgroundRefreshStrategy : NSObject<PermissionStrategy>
14+
15+
@end
16+
17+
NS_ASSUME_NONNULL_END
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// BackgroundRefreshStrategy.m
3+
// permission_handler_apple
4+
//
5+
// Created by Sebastian Roth on 28/09/2023.
6+
//
7+
8+
#import "BackgroundRefreshStrategy.h"
9+
10+
@implementation BackgroundRefreshStrategy
11+
12+
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
13+
return [BackgroundRefreshStrategy permissionStatus];
14+
}
15+
16+
- (void)checkServiceStatus:(PermissionGroup)permission completionHandler:(ServiceStatusHandler)completionHandler {
17+
completionHandler(ServiceStatusNotApplicable);
18+
}
19+
20+
- (void)requestPermission:(PermissionGroup)permission completionHandler:(PermissionStatusHandler)completionHandler {
21+
completionHandler([BackgroundRefreshStrategy permissionStatus]);
22+
}
23+
24+
+ (PermissionStatus) permissionStatus {
25+
UIBackgroundRefreshStatus status = UIApplication.sharedApplication.backgroundRefreshStatus;
26+
switch (status) {
27+
case UIBackgroundRefreshStatusDenied:
28+
return PermissionStatusDenied;
29+
case UIBackgroundRefreshStatusRestricted:
30+
return PermissionStatusRestricted;
31+
case UIBackgroundRefreshStatusAvailable:
32+
return PermissionStatusGranted;
33+
default:
34+
return PermissionStatusDenied;
35+
}
36+
}
37+
38+
@end

permission_handler_apple/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: permission_handler_apple
22
description: Permission plugin for Flutter. This plugin provides the iOS API to request and check permissions.
33
repository: https://github.com/baseflow/flutter-permission-handler
44
issue_tracker: https://github.com/Baseflow/flutter-permission-handler/issues
5-
version: 9.3.1
5+
version: 9.4.0
66

77

88
environment:
@@ -19,7 +19,7 @@ flutter:
1919
dependencies:
2020
flutter:
2121
sdk: flutter
22-
permission_handler_platform_interface: ^4.1.0
22+
permission_handler_platform_interface: ^4.2.0
2323

2424
dev_dependencies:
2525
flutter_lints: ^1.0.4

0 commit comments

Comments
 (0)