Skip to content

Commit

Permalink
Added notification background mode #66
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Jun 27, 2021
1 parent 663dbdd commit 3b776f1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<key>PufferyWidgetExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>8</integer>
<integer>9</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
Expand Down
4 changes: 4 additions & 0 deletions Puffery/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
pufferyApp.didRegisterForRemoteNotifications(with: deviceToken)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
Widgets.reloadAll()
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
Widgets.reloadAll()
completionHandler(.newData)
Expand Down
4 changes: 4 additions & 0 deletions Puffery/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
2 changes: 0 additions & 2 deletions Puffery/Puffery.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
Expand Down
2 changes: 0 additions & 2 deletions Puffery/PufferyDebug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.personal-information.photos-library</key>
Expand Down
5 changes: 2 additions & 3 deletions PufferyKit/Sources/PlatformSupport/NotificationsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import UserNotifications
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
defer {
DispatchQueue.main.async(execute: Widgets.reloadAll)
}
if let subscribedChannel = ReceivedMessageNotification(content: response.notification.request.content) {
NotificationCenter.default.post(name: .receivedMessage, object: nil, userInfo: [
"ReceivedMessageNotification": subscribedChannel,
])
DispatchQueue.main.async(execute: Widgets.reloadAll)
completionHandler()
} else {
DispatchQueue.main.async(execute: Widgets.reloadAll)
completionHandler()
}
}
Expand Down
3 changes: 2 additions & 1 deletion ReceivedMessageNotification.apns
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"body": "Some new details",
},
"sound": "default",
"badge": 1
"badge": 1,
"content-available": 1
},
"subscribedChannelID": "912732A6-7A55-4A97-B80C-327BE73525EF",
"receivedMessageID": "DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF"
Expand Down

0 comments on commit 3b776f1

Please sign in to comment.