bug(geolocation): iOS requestPermissions never settles after "Allow Once" lapses, and the plugin prompts unasked
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in GeolocationPlugin.swift: read requestPermissions, bindAuthorisationStatusPublisher (the .notDetermined sink), and handleLocationRequest, along with the callback manager's requestPermissionsCallbacks, locationCallbacks and watchCallbacks. Reproduce on an iOS simulator by choosing "Allow Once", backgrounding the app, then calling requestPermissions again. Done means that call resolves or shows a prompt when the status is .notDetermined, and that no system prompt appears without a pending JS call.
由索引模型根据 Issue 内容生成。
描述
Bug Report
Plugin(s)
@capacitor/geolocation 8.2.4 (iOS). The same code is in 9.0.0-next.3.
Capacitor Version
@capacitor/core and @capacitor/ios 8.5.3; iPhone 16 Pro simulator, iOS 18.3.
Platform(s)
iOS
Current Behavior
Two problems, both from how GeolocationPlugin.swift handles the .notDetermined status.
1. requestPermissions() (and getCurrentPosition()) never settle after "Allow Once" lapses.
- Call
requestPermissions()and choose Allow Once, thengetCurrentPosition(): works. - Send the app to the background (for example, open Apple Maps). About 10 seconds later iOS ends the one-time grant and the status becomes
.notDetermined. - The plugin's
authorisationStatusPublishersink sees.notDeterminedand callsrequestLocationAuthorisationby itself. The app is not in use, so locationd drops it:locationd: {"msg":"#AuthPrompt #Warning Dropping authorization request placed while insufficiently in-use", "ClientKeyPath":"i<bundle id>:", "requestType":2, "inUseLevel":0} - Back in the app, call
checkPermissions()(returnsprompt), thenrequestPermissions(). Because the status is already.notDetermined,requestPermissionsonly adds the call torequestPermissionsCallbacksand waits for the publisher. The publisher never fires again, since nothing changes, and no new authorisation request is made. The promise never resolves or rejects.getCurrentPositionparks the same way (default: breakinhandleLocationRequest), and itstimeoutdoes not help because the timer only starts inrequestSingleLocation, after authorisation.
Every later call hangs too, until the app process is restarted.
2. A permission prompt appears without any call.
Once any plugin method has been called in the process, the sink stays subscribed. Whenever the status changes to .notDetermined while the app is active, the sink requests authorisation, and the system prompt appears over whatever screen is open, with no JS call behind it:
locationd: {"msg":"Showing #AuthPrompt", "requestType":2, "Client":"i<bundle id>:"}
Expected Behavior
requestPermissions()shows the prompt (or resolves) whenever the status is.notDeterminedat the time of the call.- The plugin only asks for authorisation on behalf of a pending call.
Code Reproduction
await Geolocation.requestPermissions({ permissions: ['coarseLocation'] }); // choose "Allow Once"
await Geolocation.getCurrentPosition(); // works
// background the app for ~10 s, return
await Geolocation.checkPermissions(); // { coarseLocation: 'prompt' }
await Geolocation.requestPermissions({ permissions: ['coarseLocation'] }); // never settles
Additional Context
The patch we ship (patch-package), which fixes both cases in our testing:
@@ requestPermissions
if locationService?.authorisationStatus == .notDetermined {
shouldSetupBindings()
callbackManager?.addRequestPermissionsCallback(capacitorCall: call)
+ requestLocationAuthorisation(type: .whenInUse)
} else {
@@ bindAuthorisationStatusPublisher
case .notDetermined:
- self.requestLocationAuthorisation(type: .whenInUse)
+ if self.hasPendingCallbacks() {
+ self.requestLocationAuthorisation(type: .whenInUse)
+ }
@@ handleLocationRequest
case .restricted: callbackManager?.sendError(.permissionRestricted)
+ case .notDetermined: requestLocationAuthorisation(type: .whenInUse)
default: break
@@
+ func hasPendingCallbacks() -> Bool {
+ guard let callbackManager else { return false }
+ return !callbackManager.requestPermissionsCallbacks.isEmpty
+ || !callbackManager.locationCallbacks.isEmpty
+ || !callbackManager.watchCallbacks.isEmpty
+ }
- 主要语言
- Java
- 星标
- 688
- 派生
- 691
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 3
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ionic-team/capacitor-plugins 的其他 Issue
-
triage
难度 2/5 1-3 小时 新手友好度 80/100
ionic-team/capacitor-plugins#2627 ·
维护者通常 1 天内回复
-
triage
难度 2/5 1-3 小时 新手友好度 72/100
ionic-team/capacitor-plugins#2616 ·
维护者通常 1 天内回复
-
[@capacitor/app] iOS: 'Expression implicitly coerced from String? to Any' warning in getAppLanguage未关闭triage
难度 1/5 1 小时以内 新手友好度 88/100
ionic-team/capacitor-plugins#2604 ·
维护者通常 1 天内回复
-
bug(action-sheet, camera): on iPhone with Liquid Glass, action sheets show as a popover without the Cancel action可能已有人在做 @arblitroshani 于 1 天前认领。 未关闭platform: ios
难度 3/5 1-2 天 新手友好度 20/100
ionic-team/capacitor-plugins#2630 ·
维护者通常 1 天内回复
-
bug(status-bar): iOS WebView moves under the status bar after a full-screen modal is dismissed可能已有人在做 @kidzki 于 1 天前认领。 未关闭platform: ios
难度 3/5 1-2 天 新手友好度 25/100
ionic-team/capacitor-plugins#2625 ·
维护者通常 1 天内回复
查看 ionic-team/capacitor-plugins 的全部 Issue
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
enhancement good first issue
难度 2/5 1-3 小时 新手友好度 72/100
ahmedmmordi/store-app#8 ·
-
jhipster heroku fails on heroku git:remote when reusing an existing app outside a git repository未关闭area: triage theme: undefined
难度 2/5 1-3 小时 新手友好度 76/100
jhipster/generator-jhipster#36018 ·
维护者通常 1 天内回复
-
component/zeebe kind/feature scope/broker
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复