Twin: synonymdev/bitkit-android#1350
Refs: #799
Problem or use case
Bitkit finds Paykit payment requests only while it is open: requests are discovered by polling the contact's homeserver, and no push exists for them. An allower who is not in the app never learns that a request is waiting, whether an allowance covers it or not.
Proposed solution
First version of background support for allowances: poll for new Paykit requests in the background and notify. No payment happens in the background.
- One local notification per new request, such as "{contact} requests $2 · Open Bitkit to pay it". For a request an allowance covers, the text says it is paid automatically when Bitkit opens.
- Each request notifies once. Tapping the notification opens Bitkit on that request's Payment Request sheet.
- Nothing is posted when notifications are not allowed.
Platform details (iOS):
- Bitkit registers no background task today. Add a
BGAppRefreshTask: its identifier in BGTaskSchedulerPermittedIdentifiers, the fetch background mode, registration at launch, and a new request with an earliestBeginDate of about 15 minutes after each run.
- iOS decides when the task runs and never runs it after the user force-quits the app, so timing is best effort.
- The task starts Paykit only, never the Lightning node, and finishes within about 30 seconds: it sets an
expirationHandler and calls setTaskCompleted(success:).
- Paykit's keychain items use
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, so the task can read them in the background once the device was unlocked after boot.
- The Notification Service Extension cannot do this: it receives no Paykit push, and it does not start the node because of the extension's memory and time limits.
- The existing presented-requests record (
paykitPresentedPaymentRequests) can also mark a request as notified.
Done when:
- A request sent while Bitkit is backgrounded or closed produces exactly one notification within the platform's polling window.
- Opening Bitkit from that notification shows the request, or pays it when an allowance covers it.
- A request that was already notified, or already handled in the app, does not notify again.
Alternatives considered
- A server-side push when a request lands, for example from Paykit Server or the Blocktank notifier watching the homeserver. It would notify within seconds, but it needs backend and protocol work; tracked separately.
- Paying covered requests in the background. Left for a follow-up.
Additional context
- Builds on the implementation in the refs above.
Twin: synonymdev/bitkit-android#1350
Refs: #799
Problem or use case
Bitkit finds Paykit payment requests only while it is open: requests are discovered by polling the contact's homeserver, and no push exists for them. An allower who is not in the app never learns that a request is waiting, whether an allowance covers it or not.
Proposed solution
First version of background support for allowances: poll for new Paykit requests in the background and notify. No payment happens in the background.
Platform details (iOS):
BGAppRefreshTask: its identifier inBGTaskSchedulerPermittedIdentifiers, thefetchbackground mode, registration at launch, and a new request with anearliestBeginDateof about 15 minutes after each run.expirationHandlerand callssetTaskCompleted(success:).kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, so the task can read them in the background once the device was unlocked after boot.paykitPresentedPaymentRequests) can also mark a request as notified.Done when:
Alternatives considered
Additional context