Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sample] Notify notification tap #1228

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Example/IntegrationTests/Push/NotifyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ final class NotifyTests: XCTestCase {
override func setUp() {
pk = try! EthereumPrivateKey()
walletNotifyClientA = makeWalletClient()
publishers.removeAll()
}

func testWalletCreatesSubscription() async throws {
Expand Down
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>