Skip to content

Commit c1c1c7e

Browse files
authored
ci: add document generation lane (#9)
* ci: add document generation lane * doc: update usage in README
1 parent 415ce72 commit c1c1c7e

11 files changed

+261
-11
lines changed

.circleci/config.yml

+16
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ jobs:
4646
name: Publish new version to cocoapods trunk
4747
command: bundle exec fastlane ios release
4848

49+
publish-doc:
50+
<<: *default-executor
51+
52+
steps:
53+
- checkout
54+
- ruby/install-deps
55+
- run:
56+
name: Publish documention for new version
57+
command: bundle exec fastlane ios publish_doc
58+
4959

5060
workflows:
5161
build-test-deploy:
@@ -59,3 +69,9 @@ workflows:
5969
requires:
6070
- build-test-ios
6171
- build-test-macos
72+
- publish-doc:
73+
filters:
74+
branches:
75+
only: release
76+
requires:
77+
- release

.jazzy.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module: AmplifyUtilsNotifications
2+
author: Amazon Web Services
3+
github_url: https://github.com/aws-amplify/amplify-swift-utils-notifications
4+
5+
exclude:
6+
- Pods
7+
8+
clean: true
9+
skip_undocumented: false
10+
undocumented_text: ""
11+
hide_documentation_coverage: true
12+
sdk: iphone
13+
theme: apple

AmplifyUtilsNotifications.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Pod::Spec.new do |spec|
66

77
spec.description = "<<-DESC
88
Amplify Swift Utilities for Notifications provides helpful functionality for working with push notifications on iOS and macOS.
9-
Although it was developed for use with AWS Amplify, it can also be used indepdendently.
9+
Although it was developed for use with AWS Amplify, it can also be used independently.
1010
1111
The following features are provided:
1212
* Service extension to support fetching and attaching remote media to notifications

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ source 'https://rubygems.org'
22

33
gem 'cocoapods', '~> 1.11.3'
44
gem 'fastlane', '~> 2.211'
5-
5+
gem 'jazzy', '~> 0.14.3'
66
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
77
eval_gemfile(plugins_path) if File.exist?(plugins_path)

Gemfile.lock

+22
Original file line numberDiff line numberDiff line change
@@ -211,25 +211,40 @@ GEM
211211
httpclient (2.8.3)
212212
i18n (1.12.0)
213213
concurrent-ruby (~> 1.0)
214+
jazzy (0.14.3)
215+
cocoapods (~> 1.5)
216+
mustache (~> 1.1)
217+
open4 (~> 1.3)
218+
redcarpet (~> 3.4)
219+
rexml (~> 3.2)
220+
rouge (>= 2.0.6, < 4.0)
221+
sassc (~> 2.1)
222+
sqlite3 (~> 1.3)
223+
xcinvoke (~> 0.3.0)
214224
jmespath (1.6.1)
215225
json (2.6.2)
216226
jwt (2.5.0)
227+
liferaft (0.0.6)
217228
memoist (0.16.2)
218229
mini_magick (4.11.0)
219230
mini_mime (1.1.2)
231+
mini_portile2 (2.8.0)
220232
minitest (5.16.3)
221233
molinillo (0.8.0)
222234
multi_json (1.15.0)
223235
multipart-post (2.0.0)
236+
mustache (1.1.1)
224237
nanaimo (0.3.0)
225238
nap (1.1.0)
226239
naturally (2.2.1)
227240
netrc (0.11.0)
241+
open4 (1.3.4)
228242
optparse (0.1.1)
229243
os (1.1.4)
230244
plist (3.6.0)
231245
public_suffix (4.0.7)
232246
rake (13.0.6)
247+
redcarpet (3.5.1)
233248
representable (3.2.0)
234249
declarative (< 0.1.0)
235250
trailblazer-option (>= 0.1.1, < 0.2.0)
@@ -240,6 +255,8 @@ GEM
240255
ruby-macho (2.5.1)
241256
ruby2_keywords (0.0.5)
242257
rubyzip (2.3.2)
258+
sassc (2.4.0)
259+
ffi (~> 1.9)
243260
security (0.1.3)
244261
signet (0.17.0)
245262
addressable (~> 2.8)
@@ -249,6 +266,8 @@ GEM
249266
simctl (1.6.8)
250267
CFPropertyList
251268
naturally
269+
sqlite3 (1.5.3)
270+
mini_portile2 (~> 2.8.0)
252271
terminal-notifier (2.0.0)
253272
terminal-table (1.8.0)
254273
unicode-display_width (~> 1.1, >= 1.1.1)
@@ -268,6 +287,8 @@ GEM
268287
unicode-display_width (1.8.0)
269288
webrick (1.7.0)
270289
word_wrap (1.0.0)
290+
xcinvoke (0.3.0)
291+
liferaft (~> 0.0.6)
271292
xcodeproj (1.22.0)
272293
CFPropertyList (>= 2.3.3, < 4.0)
273294
atomos (~> 0.1.3)
@@ -288,6 +309,7 @@ DEPENDENCIES
288309
cocoapods (~> 1.11.3)
289310
fastlane (~> 2.211)
290311
fastlane-plugin-release_actions!
312+
jazzy (~> 0.14.3)
291313

292314
BUNDLED WITH
293315
1.17.2

README.md

+175-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,184 @@
1-
## My Project
1+
## Amplify Swift Utilities for Notifications
22

3-
TODO: Fill this README out!
3+
Amplify Swift Utilities for Notifications provides helpful functionality for working with push notifications on iOS and macOS.
44

5-
Be sure to:
5+
Although it was developed for use with AWS Amplify, it can also be used independently.
66

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
97

10-
## Security
8+
[API Documentation](https://aws-amplify.github.io/amplify-swift-utils-notifications/docs/)
9+
10+
11+
## Features
12+
13+
- Convenience methods to support requesting notification permissions and registering with APNs
14+
- Push Notification Service extension to support fetching and attaching remote media to notifications
15+
16+
17+
## Platform Support
18+
Amplify Swift Utilities for Notifications package supports iOS 13+ and macOS 10.15+.
1119

12-
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
1320

1421
## License
1522

16-
This project is licensed under the Apache-2.0 License.
23+
This package is licensed under the Apache-2.0 License.
24+
25+
26+
## Installation
27+
28+
This package requires Xcode 13.4 or higher to build.
29+
30+
31+
### Swift Package Manager
32+
1. Swift Package Manager is distributed with Xcode. To start adding this package to your iOS project, open your project in Xcode and select **File > Add Packages**.
33+
![add-packages](./readme-images/add-packages.png)
34+
35+
2. Enter the package GitHub repo URL (https://github.com/aws-amplify/amplify-swift-utils-notifications) into the search bar.
36+
37+
3. You'll see the repository rules for which version you want Swift Package Manager to install. Choose **Up to Next Major Version** and enter **1.0.0** as the minimum version for the Dependency Rule, then click **Add Package**.
38+
![amplify-swift-utils-notifications](./readme-images/amplify-swift-utils-notifications.png)
39+
40+
4. Select `AmplifyUtilsNotifications`, then click Add Package.
41+
42+
5. In your app code, explicitly import the plugin as needed.
43+
44+
```swift
45+
import SwiftUI
46+
import AmplifyUtilsNotifications
47+
48+
@main
49+
struct HelloWorldApp: App {
50+
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
51+
var body: some Scene {
52+
WindowGroup {
53+
ContentView()
54+
}
55+
}
56+
}
57+
58+
class AppDelegate: NSObject, UIApplicationDelegate {
59+
func applicationDidFinishLaunching(_ application: UIApplication) {
60+
Task {
61+
let isPushNotificationAllowed = await AmplifyUtilsNotifications.AUNotificationPermissions.allowed
62+
// ...
63+
}
64+
}
65+
}
66+
```
67+
68+
### Cocoapods
69+
1. This package is also available through [CocoaPods](https://cocoapods.org/). If you have not installed CocoaPods, follow the instructions [here](https://guides.cocoapods.org/using/getting-started.html#getting-started).
70+
71+
2. Add the package as a dependency to your Podfile.
72+
```ruby
73+
platform :ios, '13.0'
74+
use_frameworks!
75+
76+
target 'HelloWorldApp' do
77+
pod 'AmplifyUtilsNotifications', '~> 1.0.0'
78+
end
79+
```
80+
81+
3. Then run the following command:
82+
```sh
83+
pod install
84+
```
85+
86+
4. Open up *.xcworkspace with Xcode, and you will be able to use the `AmplifyUtilsNotifications` package in your project.
87+
88+
## Notification Service Extension for AWS Pinpoint
89+
90+
This package includes a ready to use implementation(`AUNotificationService`) for handling remote notifications sent by AWS Pinpoint. It helps with decoding notification json data and retrieving the remote media url as an attachment.
91+
92+
#### Push notification in AWS Pinpoint format
93+
1. Add a Service App Extension to Your Project. [Apple Doc](https://developer.apple.com/documentation/usernotifications/modifying_content_in_newly_delivered_notifications).
94+
95+
![add-notification-service-extension](./readme-images/add-notification-service-extension.png)
96+
97+
2. Update `info.plist` of the newly created Notification Service Extension.
98+
99+
```xml
100+
<dict>
101+
<key>NSExtension</key>
102+
<dict>
103+
<key>NSExtensionPointIdentifier</key>
104+
<string>com.apple.usernotifications.service</string>
105+
<key>NSExtensionPrincipalClass</key>
106+
<string>AmplifyUtilsNotifications.AUNotificationService</string>
107+
</dict>
108+
</dict>
109+
```
110+
111+
> Note:
112+
>
113+
> We suggest you either keep the auto generated `NotificationService.swift` source file or add an empty swift file for your Notification Service Extension target. An empty source list will cause an error when you try to install the extension to a real device.
114+
115+
### Push notification not in AWS Pinpoint format
116+
117+
You can also subclass `AUNotificationService` to support a different notification payload format or add custom functionality.
118+
119+
For example, we want to send the push notification with a field name `video_url`.
120+
121+
1. Define a `MyPayload` struct that conforms to the `AUNotificationPayload` protocol. It defines the `remoteMediaURL`.
122+
123+
2. Subclass `AUNotificationService` and change the `payloadSchema` property to `MyPayload` that was defined in the previous step.
124+
125+
```swift
126+
import AmplifyUtilsNotifications
127+
128+
struct MyPayload: AUNotificationPayload {
129+
var remoteMediaURL: String? {
130+
video_url
131+
}
132+
133+
let video_url: String
134+
}
135+
136+
class NotificationService: AUNotificationService {
137+
138+
override init() {
139+
super.init()
140+
self.payloadSchema = MyPayload.self
141+
}
142+
}
143+
```
144+
145+
3. Update the `info.plist` by setting `NSExtensionPrincipalClass` to `$(PRODUCT_MODULE_NAME).NotificationService`.
146+
147+
You can also override the `didReceive` function to modify the content as desired. For example, attach suffix `[MODIFIED]` to your notification title.
148+
149+
```swift
150+
override func didReceive(
151+
_ request: UNNotificationRequest,
152+
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
153+
) {
154+
super.didReceive(request) { content in
155+
self.contentHandler = contentHandler
156+
let mutableContent = content.mutableCopy() as? UNMutableNotificationContent
157+
mutableContent?.title = content.title + "[MODIFIED]"
158+
if let mutableContent {
159+
contentHandler(mutableContent)
160+
}
161+
}
162+
}
163+
```
164+
165+
166+
167+
168+
## Reporting Bugs/Feature Requests
169+
170+
[![Open Bugs](https://img.shields.io/github/issues/aws-amplify/amplify-swift-utils-notifications/bug?color=d73a4a&label=bugs)](https://github.com/aws-amplify/amplify-swift-utils-notifications/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
171+
[![Open Questions](https://img.shields.io/github/issues/aws-amplify/amplify-swift-utils-notifications/usage%20question?color=558dfd&label=questions)](https://github.com/aws-amplify/amplify-swift-utils-notifications/issues?q=is%3Aissue+label%3A%22question%22+is%3Aopen+)
172+
[![Feature Requests](https://img.shields.io/github/issues/aws-amplify/amplify-swift-utils-notifications/feature%20request?color=ff9001&label=feature%20requests)](https://github.com/aws-amplify/amplify-swift-utils-notifications/issues?q=is%3Aissue+label%3A%22feature-request%22+is%3Aopen+)
173+
[![Closed Issues](https://img.shields.io/github/issues-closed/aws-amplify/amplify-swift-utils-notifications?color=%2325CC00)](https://github.com/aws-amplify/amplify-swift-utils-notifications/issues?q=is%3Aissue+is%3Aclosed+)
174+
175+
We welcome you to use the GitHub issue tracker to report bugs or suggest features.
176+
177+
When filing an issue, please check [existing open](https://github.com/aws-amplify/amplify-swift-utils-notifications/issues), or [recently closed](https://github.com/aws-amplify/amplify-swift-utils-notifications/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
178+
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:
17179

180+
* Expected behavior and observed behavior
181+
* A reproducible test case or series of steps
182+
* The version of our code being used
183+
* Any modifications you've made relevant to the bug
184+
* Anything custom about your environment or deployment

fastlane/Fastfile

+25-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,37 @@ platform :ios do
3131
# sync_up_main_release_branch
3232
end
3333

34+
desc "Generate and publish documentaion for new version"
35+
lane :publish_doc do
36+
new_version = generate_doc
37+
git_add(path: "docs/*")
38+
git_commit(path: "docs/*", message: "chore: update API document for #{new_version} [skip ci]")
39+
# push_to_git_remote(
40+
# local_branch: "release",
41+
# remote_branch: "gh-pages",
42+
# tags: true,
43+
# force: true,
44+
# )
45+
end
46+
47+
desc "Generate jazzy documentaion"
48+
private_lane :generate_doc do
49+
pod_version = version_get_podspec(path: PODSPEC_PATH)
50+
jazzy(config: ".jazzy.yaml", module_version: pod_version)
51+
Dir.chdir('..') do
52+
sh('ln', '-s', '../readme-images', 'docs')
53+
end
54+
pod_version
55+
end
56+
3457
desc "Generate commit for version bump"
3558
private_lane :generate_version_bump_commit do |options|
3659
next_version = options[:version]
3760
UI.user_error!("version shouldn't be nil") if next_version.nil?
3861

3962
version_bump_podspec(path: PODSPEC_PATH, version_number: next_version)
4063
UI.message "Set version to: #{next_version}"
64+
git_add(path: PODSPEC_PATH)
4165
git_commit(path: PODSPEC_PATH, message: "chore: bump version to #{next_version} [skip ci]")
4266
end
4367

@@ -52,7 +76,7 @@ platform :ios do
5276

5377
changelog = build_changelog(version: next_version, commits: commits)
5478
write_changelog(changelog: changelog, path: CHANGELOG_PATH)
55-
79+
git_add(path: CHANGELOG_PATH)
5680
git_commit(path: CHANGELOG_PATH, message: "changelog: update changelog for #{next_version} [skip ci]")
5781
end
5882

fastlane/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ Run all the tests on iOS
3131

3232
Publish to Cocoapods whenever a new version tag is created
3333

34+
### ios publish_doc
35+
36+
```sh
37+
[bundle exec] fastlane ios publish_doc
38+
```
39+
40+
Generate and publish documentaion for new version
41+
3442
----
3543

3644

Loading

readme-images/add-packages.png

89.9 KB
Loading
Loading

0 commit comments

Comments
 (0)