diff --git a/Example/IntegrationTests/Push/NotifyTests.swift b/Example/IntegrationTests/Push/NotifyTests.swift index 18408e9af..006631957 100644 --- a/Example/IntegrationTests/Push/NotifyTests.swift +++ b/Example/IntegrationTests/Push/NotifyTests.swift @@ -95,6 +95,7 @@ final class NotifyTests: XCTestCase { override func setUp() { pk = try! EthereumPrivateKey() walletNotifyClientA = makeWalletClient() + publishers.removeAll() } func testWalletCreatesSubscription() async throws { diff --git a/Example/PNDecryptionService/NotificationService.swift b/Example/PNDecryptionService/NotificationService.swift index 70232ec62..cd2830ef2 100644 --- a/Example/PNDecryptionService/NotificationService.swift +++ b/Example/PNDecryptionService/NotificationService.swift @@ -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) diff --git a/Example/WalletApp/ApplicationLayer/SceneDelegate.swift b/Example/WalletApp/ApplicationLayer/SceneDelegate.swift index 4a98cfa19..c36e6b4f6 100644 --- a/Example/WalletApp/ApplicationLayer/SceneDelegate.swift +++ b/Example/WalletApp/ApplicationLayer/SceneDelegate.swift @@ -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() @@ -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) { 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) + } } } diff --git a/Example/WalletApp/Other/Info.plist b/Example/WalletApp/Other/Info.plist index 25606209f..f542d355a 100644 --- a/Example/WalletApp/Other/Info.plist +++ b/Example/WalletApp/Other/Info.plist @@ -2,10 +2,6 @@ - NSUserActivityTypes - - INSendMessageIntent - CFBundleIconName AppIcon CFBundleURLTypes @@ -23,19 +19,21 @@ $(CONFIGURATION) ITSAppUsesNonExemptEncryption + MIXPANEL_TOKEN + $(MIXPANEL_TOKEN) NSAppTransportSecurity NSAllowsArbitraryLoads + NSUserActivityTypes + + INSendMessageIntent + PROJECT_ID $(PROJECT_ID) - WALLETAPP_SENTRY_DSN - $(WALLETAPP_SENTRY_DSN) SIMULATOR_IDENTIFIER $(SIMULATOR_IDENTIFIER) - MIXPANEL_TOKEN - $(MIXPANEL_TOKEN) UIApplicationSceneManifest UIApplicationSupportsMultipleScenes @@ -53,9 +51,7 @@ - UIBackgroundModes - - remote-notification - + WALLETAPP_SENTRY_DSN + $(WALLETAPP_SENTRY_DSN)