Widget.md
This commit is contained in:
parent
c3d4834879
commit
300d1eac60
|
@ -4,39 +4,32 @@
|
|||
|
||||
The NetNewsWire iOS widget supports the `systemSmall` and `systemMedium` styles.
|
||||
|
||||
The `systemSmall` style displays the current Today and Unread counts; `systemMedium` displays the latest two articles.
|
||||
For the purpose of this PoC: the `systemSmall` style displays the current Today and Unread counts; `systemMedium` displays the latest two articles.
|
||||
|
||||
## Passing Data from the App to the Widget
|
||||
|
||||
Data is made available to the widget by encoding JSON data and saving it to a file in a directory available to app extensions.
|
||||
Data is made available to the widget by encoding smart feed and article data as JSON, and saving it to a file in a directory available to app extensions.
|
||||
|
||||
Three `struct`s are responsible for this:
|
||||
|
||||
```
|
||||
struct WidgetData: Codable {
|
||||
|
||||
let currentUnreadCount: Int
|
||||
let currentTodayCount: Int
|
||||
let latestArticles: [LatestArticle]
|
||||
let lastUpdateTime: Date
|
||||
|
||||
}
|
||||
|
||||
struct LatestArticle: Codable {
|
||||
|
||||
let feedTitle: String
|
||||
let articleTitle: String?
|
||||
let articleSummary: String?
|
||||
let feedIcon: Data? // Base64 encoded image data
|
||||
let pubDate: String
|
||||
|
||||
}
|
||||
```
|
||||
- `WidgetDataEncoder` (which is available to the app);
|
||||
- `WidgetDataDecoder` (which is available to the widget); and,
|
||||
- `WidgetData` (which is available to both app and widget, and includes the data neccessary for the widget to function)
|
||||
|
||||
## When is JSON Data Saved?
|
||||
|
||||
1. When the app enters the background
|
||||
2. After a background refresh
|
||||
1. When the app enters the background (monitored via the `scenePhase` changing (tested)); or,
|
||||
2. After a background refresh (untested at the time of writing)
|
||||
|
||||
Encoding tasks are fenced in
|
||||
```
|
||||
UIApplication.shared.beginBackgroundTask
|
||||
_{ encoding task }_
|
||||
UIApplication.shared.endBackgroundTask
|
||||
```
|
||||
in order to ensure that the file can be written with sufficient time to spare.
|
||||
|
||||
After JSON data is saved, Widget timelines are reloaded.
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue