Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/permission_handler_watchos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ physical watch.
so an app that compiles "always" in declares
`NSPrivacyAccessedAPICategoryUserDefaults` (`CA92.1`) in its privacy
manifest.
* With "when in use" granted, `locationAlways` reads `denied` until it is
asked for, as in permission_handler_apple 9.6.4, so an app can still ask
for it; once asked for and kept at "while using", it reads
`permanentlyDenied`. A request watchOS shows no prompt for, because
"always" was asked for before by other code or before a reinstall,
answers with the status after two seconds instead of waiting.
* A request whose usage description is missing fails with
`MISSING_USAGE_DESCRIPTION` instead of the app being terminated. A request
while another waits fails with `ERROR_ALREADY_REQUESTING_PERMISSIONS`, as
Expand Down
16 changes: 12 additions & 4 deletions packages/permission_handler_watchos/PORTING_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
| watchOS capability | ◐ The permissions watchOS has: location (when in use and always), notifications, critical alerts, sensors, microphone, contacts, calendar (full access and write only), reminders, Bluetooth, Siri; storage is granted as on iOS. The others answer as iOS answers for a permission it does not know |
| Host unit tests (`flutter test`) | ✅ 15 pass; 7 of them check the pubspec's `defines` against the native guards: each macro lists a key, and each key is filed under one macro, the one the guards around the code that reads it leave it; and the write-only request is compiled in with either calendar macro, as on iOS |
| Upstream integration test | ○ none upstream (Baseflow's example is a manual demo) |
| watchOS integration test (`example/integration_test/permission_handler_test.dart`) | ✅ 5 pass on the watchOS 27.0 Simulator |
| System prompts | ✅ asked for on the Simulator, each answered as on iOS: notification granted; location when in use granted; location always kept at "while using" → permanentlyDenied; sensors granted; microphone granted; contacts refused → permanentlyDenied; reminders granted; calendar write only granted. Bluetooth reads granted on the Simulator, which has no Bluetooth. After the review fixes, location when in use again: the prompt closed with the crown → answered, and a second request prompted again; allowed → granted; "always" asked for right after → its prompt stayed up until answered, kept at "while using" → permanentlyDenied. In upstream's example: calendar (full access) allowed → granted |
| watchOS integration test (`example/integration_test/permission_handler_test.dart`) | ✅ on the watchOS 27.0 Simulator, 5 pass and 1 skips with location reset, and 5 pass and 1 skips with it allowed "while using": each location case runs in one of the two |
| System prompts | ✅ asked for on the Simulator, each answered as on iOS: notification granted; location when in use granted; location always kept at "while using" → permanentlyDenied; sensors granted; microphone granted; contacts refused → permanentlyDenied; reminders granted; calendar write only granted. Bluetooth reads granted on the Simulator, which has no Bluetooth. After the review fixes, location when in use again: the prompt closed with the crown → answered, and a second request prompted again; allowed → granted; "always" asked for right after → its prompt stayed up until answered, kept at "while using" → permanentlyDenied. With "when in use" allowed and "always" not yet asked for, `locationAlways` read `denied`; asked for and kept at "while using" → permanentlyDenied, its status then permanentlyDenied, and a second request answered without a prompt. With that prompt up for over two seconds, the request still waited for the answer: kept at "while using" → permanentlyDenied, changed to "always" → granted. After a reinstall that kept location, watchOS showed no "always" prompt; the request answered permanentlyDenied after two seconds, where it had waited with no answer before. In upstream's example: calendar (full access) allowed → granted |
| Critical alerts and Siri prompts | not yet asked for: each needs an entitlement the example does not have |
| Compile-time groups | ✅ `tool/check_native_sources.sh` compiles the sources with no `-D` (flutter-watchos 0.1.1 or earlier), with the marker and every macro, with the marker alone, and with the marker and each macro alone, for a watch and the Simulator; each pair of the events macros was compiled too (Xcode 27.1, no warning). Objects compiled with the marker alone hold none of the groups' class names, selectors or keys (`strings`), and none of their frameworks' link entries; with `PERMISSION_LOCATION_WHENINUSE` alone, no "always" request and no `NSUserDefaults` reference (`nm -u`). The events strategy, built for macOS with EventKit's status and requests stubbed, answered every combination of its three macros as the iOS implementation does when the Info.plist has every key: each status read, the service not applicable, a request whose prompt is left out answering its status without a prompt. When the Info.plist has only the keys of the macros that are on, it differs in one case: with the full-access key and no write-only key, a `calendarWriteOnly` request while it is not determined fails with `MISSING_USAGE_DESCRIPTION`, where iOS sends the write-only request (see Design) |
| Privacy footprint against a native app (in place of an App Store Connect upload) | ✅ 2026-10-30, with `nm -u`, `otool` and `strings -a`. A native SwiftUI watch app that only calls `UNUserNotificationCenter.requestAuthorization` references one privacy API, `UNUserNotificationCenter`. A Flutter watch app that only requests `Permission.notification` through this package, with no usage keys, built as a debug Simulator app by a flutter-watchos that applies `defines` (`-v`: none of the 10 on), references the same and nothing else: no other group's class names, request selectors or usage keys. Both link the Swift CoreLocation overlay that SwiftUI pulls in, and reference no location class. So no upload is needed. Built by a flutter-watchos without `defines`, as 0.1.1, the same app links no other framework and references no other framework's class (`NSUserDefaults` is referenced, for the location flag), but every group's class names, request selectors and usage keys are in it as strings |
Expand Down Expand Up @@ -109,12 +109,20 @@ becoming active again after the prompt (`WKApplicationDidBecomeActiveNotificatio
is the answer then, and a second request answers without a prompt that
watchOS would not show again.

watchOS shows that prompt once, and the Simulator remembers it across a
reinstall, which clears the flag; other code in the app may have asked for
"always" too. A request watchOS shows no prompt for gets no delegate call
and no return to active, so if the app has not resigned active two seconds
after the request, the status then is the answer: `permanentlyDenied` while
"when in use" stands. The iOS implementation answers only from the delegate
or `UIApplicationDidBecomeActiveNotification`.

## Permission coverage

| Permission | watchOS |
|---|---|
| `notification` | ✅ UNUserNotificationCenter: alert, sound and badge, as on iOS; provisional is reported. The iOS implementation also registers for remote notifications after a grant; this package does not, which is firebase_messaging_watchos's job on the watch |
| `location`, `locationWhenInUse`, `locationAlways` | ✅ CLLocationManager; service status is `locationServicesEnabled` |
| `location`, `locationWhenInUse`, `locationAlways` | ✅ CLLocationManager; service status is `locationServicesEnabled`; with "when in use" granted, `locationAlways` reads `denied` until it is asked for (permission_handler_apple 9.6.4's rule) |
| `sensors` | ✅ CMMotionActivityManager, asked for with an activity query as on iOS; service status is `isActivityAvailable` |
| `microphone` | ✅ AVAudioApplication's record permission (watchOS 10 and later) |
| `contacts` | ✅ CNContactStore; the watchOS SDK has no limited access |
Expand Down Expand Up @@ -154,7 +162,7 @@ imports only `permission_handler`.

Generated by `flutter-watchos plugin port` on 2026-10-21.

Source: `permission_handler_apple` 9.6.2 (path: `/Users/iamoguzhanarslantas/.pub-cache/hosted/pub.dev/permission_handler_apple-9.6.2`)
Source: `permission_handler_apple` 9.6.2, compared through 9.6.5
Base platform: ios (Objective-C)
Output: `./permission_handler_watchos`

Expand Down
2 changes: 1 addition & 1 deletion packages/permission_handler_watchos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ with an older one, every app that uses the package:
| Permission | watchOS |
|---|---|
| `notification` | supported, provisional included |
| `location`, `locationWhenInUse`, `locationAlways` | supported, with the service status; "always" needs "when in use" first, as on iOS |
| `location`, `locationWhenInUse`, `locationAlways` | supported, with the service status; "always" needs "when in use" first, and with "when in use" granted it reads `denied` until it is asked for, as on iOS |
| `sensors` | supported (Motion & Fitness), with the service status |
| `microphone` | supported |
| `contacts` | supported; watchOS has no limited access |
Expand Down
11 changes: 11 additions & 0 deletions packages/permission_handler_watchos/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ integration test, on an Apple Watch simulator with:
flutter-watchos run -d <watch-sim>
flutter-watchos test integration_test/permission_handler_test.dart -d <watch-sim>
```

Two of the test's cases depend on location, and each skips itself unless
location is as it needs. The Simulator keeps a location answer across
installs, so set it before each run:

```sh
xcrun simctl privacy <watch-sim> reset location com.example.permissionHandlerExample.watchkitapp
flutter-watchos test integration_test/permission_handler_test.dart -d <watch-sim>
xcrun simctl privacy <watch-sim> grant location com.example.permissionHandlerExample.watchkitapp
flutter-watchos test integration_test/permission_handler_test.dart -d <watch-sim>
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
// with the app installed afresh (flutter-watchos test does that):
// flutter-watchos test integration_test/permission_handler_test.dart \
// -d <watch-sim>
// Two cases depend on location and skip themselves otherwise: one needs it
// not determined, the other allowed "while using" only. The Simulator keeps
// a location answer across installs, so set it before a run:
// xcrun simctl privacy <watch-sim> reset location \
// com.example.permissionHandlerExample.watchkitapp
// or `grant location` in place of `reset location`.

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -50,8 +56,11 @@ void main() {

testWidgets('"always" before "when in use" fails as on iOS',
(WidgetTester _) async {
// Only meaningful on a fresh install, where location is not determined.
// Only meaningful while location is not determined.
if (await Permission.locationWhenInUse.status != PermissionStatus.denied) {
markTestSkipped('location is answered already: reset it first with '
'xcrun simctl privacy <watch-sim> reset location '
'com.example.permissionHandlerExample.watchkitapp');
return;
}
await expectLater(
Expand All @@ -60,4 +69,19 @@ void main() {
'code', 'MISSING_WHENINUSE_PERMISSION')),
);
});

testWidgets('"always" can still be asked for after "when in use"',
(WidgetTester _) async {
// Only meaningful with location allowed "while using" only. A fresh
// install has not asked for "always", so it reads denied, not permanently
// denied, as in permission_handler_apple 9.6.4.
if (await Permission.locationWhenInUse.status != PermissionStatus.granted ||
await Permission.locationAlways.status == PermissionStatus.granted) {
markTestSkipped('needs location allowed "while using" only: grant it '
'first with xcrun simctl privacy <watch-sim> grant location '
'com.example.permissionHandlerExample.watchkitapp');
return;
}
expect(await Permission.locationAlways.status, PermissionStatus.denied);
});
}
43 changes: 39 additions & 4 deletions packages/permission_handler_watchos/watchos/Classes/phw_location.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@
#import <WatchKit/WatchKit.h>

#if !defined(FLUTTER_WATCHOS_PLUGIN_DEFINES) || PERMISSION_LOCATION
// Set once "always" was asked for: watchOS shows that prompt once, and a
// second request must answer without waiting for a prompt that never comes.
// Set once "always" was asked for: watchOS shows that prompt once. Until
// then "always" can still be asked for; after it, a second request must
// answer without waiting for a prompt that never comes.
static NSString* const kAskedAlwaysKey = @"dev.flutterwatch.permission_handler.askedAlways";

// How long after an "always" request the app waits to resign active, as the
// prompt taking the screen makes it, before it counts as no prompt shown.
static const NSTimeInterval kNoPromptDelay = 2.0;
#endif

// How long after the app becomes active a status still "not determined"
Expand Down Expand Up @@ -84,8 +89,23 @@ - (CLLocationManager*)manager {

- (void)checkPermission:(PHWPermission)permission done:(PHWStatusHandler)done {
CLLocationManager* manager = [self manager];
done(manager == nil ? PHWStatusDenied
: _locationStatus(permission, manager.authorizationStatus));
if (manager == nil) {
done(PHWStatusDenied);
return;
}
CLAuthorizationStatus status = manager.authorizationStatus;
#if !defined(FLUTTER_WATCHOS_PLUGIN_DEFINES) || PERMISSION_LOCATION
// "When in use" granted and "always" never asked for: it can still be
// asked for, so it reads denied, not permanently denied, as in
// permission_handler_apple 9.6.4.
if (permission == PHWPermissionLocationAlways &&
status == kCLAuthorizationStatusAuthorizedWhenInUse &&
![[NSUserDefaults standardUserDefaults] boolForKey:kAskedAlwaysKey]) {
done(PHWStatusDenied);
return;
}
#endif
done(_locationStatus(permission, status));
}

- (void)checkService:(PHWPermission)permission
Expand Down Expand Up @@ -164,6 +184,21 @@ - (void)requestAlways:(CLAuthorizationStatus)status
// app becoming active again after the prompt is the answer then.
[self observeActive];
[_manager requestAlwaysAuthorization];
// watchOS shows no prompt when "always" was asked for before without
// this flag knowing: by other code in the app, or before a reinstall
// that kept location but not NSUserDefaults. Then nothing answers, no
// delegate call and no return to active, so if the app has not resigned
// active by then, the status at that moment is the answer. An answer in
// between stands this down, as it does the re-read in observeActive.
NSUInteger answers = _answers;
__weak PHWLocationStrategy* weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kNoPromptDelay * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
PHWLocationStrategy* later = weakSelf;
if (later != nil && later->_answers == answers && !later->_resigned) {
[later answer:later->_manager.authorizationStatus];
}
});
}
#endif

Expand Down
Loading