Skip to content

Commit

Permalink
Notification tapNotification tap
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Nov 13, 2023
1 parent 53fc60e commit 0be66ed
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions Example/PNDecryptionService/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class NotificationService: UNNotificationServiceExtension {

let mutableContent = updatedContent.mutableCopy() as! UNMutableNotificationContent
mutableContent.title = pushMessage.title
mutableContent.subtitle = pushMessage.url
mutableContent.body = pushMessage.body

contentHandler(mutableContent)
Expand Down
43 changes: 35 additions & 8 deletions Example/WalletApp/ApplicationLayer/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Auth
import SafariServices
import UIKit
import WalletConnectPairing

final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
final class SceneDelegate: UIResponder, UIWindowSceneDelegate, UNUserNotificationCenterDelegate {
var window: UIWindow?

private let app = Application()
Expand Down Expand Up @@ -32,17 +33,43 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
app.requestSent = (connectionOptions.urlContexts.first?.url.absoluteString.replacingOccurrences(of: "walletapp://wc?", with: "") == "requestSent")

configurators.configure()

UNUserNotificationCenter.current().delegate = self
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let context = URLContexts.first else { return }

let uri = WalletConnectURI(urlContext: context)

if let uri {
Task {
try await Pair.instance.pair(uri: uri)
}
}
let uri = WalletConnectURI(urlContext: context)

if let uri {
Task {
try await Pair.instance.pair(uri: uri)
}
}
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
open(notification: notification)
return [.sound, .banner, .badge]
}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
open(notification: response.notification)
}
}

private extension SceneDelegate {

func open(notification: UNNotification) {
let popupTag: Int = 1020
if let url = URL(string: notification.request.content.subtitle),
let topController = window?.rootViewController?.topController, topController.view.tag != popupTag
{
let safari = SFSafariViewController(url: url)
safari.modalPresentationStyle = .formSheet
safari.view.tag = popupTag
window?.rootViewController?.topController.present(safari, animated: true)
}
}
}
20 changes: 8 additions & 12 deletions Example/WalletApp/Other/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSUserActivityTypes</key>
<array>
<string>INSendMessageIntent</string>
</array>
<key>CFBundleIconName</key>
<string>AppIcon</string>
<key>CFBundleURLTypes</key>
Expand All @@ -23,19 +19,21 @@
<string>$(CONFIGURATION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>MIXPANEL_TOKEN</key>
<string>$(MIXPANEL_TOKEN)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSUserActivityTypes</key>
<array>
<string>INSendMessageIntent</string>
</array>
<key>PROJECT_ID</key>
<string>$(PROJECT_ID)</string>
<key>WALLETAPP_SENTRY_DSN</key>
<string>$(WALLETAPP_SENTRY_DSN)</string>
<key>SIMULATOR_IDENTIFIER</key>
<string>$(SIMULATOR_IDENTIFIER)</string>
<key>MIXPANEL_TOKEN</key>
<string>$(MIXPANEL_TOKEN)</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand All @@ -53,9 +51,7 @@
</array>
</dict>
</dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>WALLETAPP_SENTRY_DSN</key>
<string>$(WALLETAPP_SENTRY_DSN)</string>
</dict>
</plist>

0 comments on commit 0be66ed

Please sign in to comment.