diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 40761c7fb..31e6dfa8d 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -769,4 +769,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2 -COCOAPODS: 1.14.2 +COCOAPODS: 1.15.2 diff --git a/example/package.json b/example/package.json index 879538764..0cdff1492 100644 --- a/example/package.json +++ b/example/package.json @@ -10,6 +10,7 @@ "dependencies": { "@react-native-async-storage/async-storage": "^1.21.0", "@react-native-community/netinfo": "^11.2.0", + "@react-native-community/push-notification-ios": "^1.11.0", "@react-navigation/native": "^6.1.6", "@react-navigation/native-stack": "^6.9.12", "@thirdweb-dev/react-native": "^0.6.2", @@ -33,8 +34,8 @@ "react-native-fs": "^2.20.0", "react-native-get-random-values": "^1.11.0", "react-native-mmkv": "^2.8.0", - "react-native-push-notification": "^8.1.1", "react-native-modal-selector": "^2.1.2", + "react-native-push-notification": "^8.1.1", "react-native-quick-base64": "^2.0.8", "react-native-quick-crypto": "^0.6.1", "react-native-randombytes": "^3.6.1", diff --git a/example/src/PushController.tsx b/example/src/PushController.tsx index 7e06f21b2..8292ac020 100644 --- a/example/src/PushController.tsx +++ b/example/src/PushController.tsx @@ -1,64 +1,63 @@ -import PushNotificationIOS from "@react-native-community/push-notification-ios"; -import { useEffect } from "react"; -import PushNotification from "react-native-push-notification"; -import { XMTPPush, Client } from "xmtp-react-native-sdk"; +import PushNotificationIOS from '@react-native-community/push-notification-ios' +import { useEffect } from 'react' +import PushNotification from 'react-native-push-notification' +import { XMTPPush, Client } from 'xmtp-react-native-sdk' function PushController({ client }: { client: Client }) { useEffect(() => { PushNotification.configure({ // (optional) Called when Token is generated (iOS and Android) onRegister(token: any) { - XMTPPush.register("YOUR_SERVER_ADDRESS", token.token as string); + XMTPPush.register('YOUR_SERVER_ADDRESS', token.token as string) PushNotification.createChannel({ - channelId: "xmtp-react-native-example-dm", // (required) - channelName: "XMTP React Native Example", // (required) - }); + channelId: 'xmtp-react-native-example-dm', // (required) + channelName: 'XMTP React Native Example', // (required) + }) }, // (required) Called when a remote or local notification is opened or received onNotification(notification: any) { - const encryptedMessage = notification.data.encryptedMessage; - const topic = notification.data.topic; + const encryptedMessage = notification.data.encryptedMessage + const topic = notification.data.topic if (encryptedMessage == null || topic == null) { - return; + return } - (async () => { - const conversations = await client.conversations.list(); + ;(async () => { + const conversations = await client.conversations.list() const conversation = conversations.find( (c: { topic: string }) => c.topic === topic - ); + ) if (conversation == null) { - return; + return } - const peerAddress = conversation.peerAddress; - const decodedMessage = await conversation.decodeMessage( - encryptedMessage - ); - const body = decodedMessage.content; + const peerAddress = conversation.peerAddress + const decodedMessage = + await conversation.decodeMessage(encryptedMessage) + const body = decodedMessage.content PushNotification.localNotification({ /* Android Only Properties */ - channelId: "xmtp-react-native-example-dm", // (required) channelId, if the channel doesn't exist, notification will not trigger. - messageId: "google:message_id", // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module. + channelId: 'xmtp-react-native-example-dm', // (required) channelId, if the channel doesn't exist, notification will not trigger. + messageId: 'google:message_id', // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module. /* iOS only properties */ - category: "", // (optional) default: empty string - subtitle: "My Notification Subtitle", // (optional) smaller title below notification title + category: '', // (optional) default: empty string + subtitle: 'My Notification Subtitle', // (optional) smaller title below notification title /* iOS and Android properties */ id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID title: peerAddress, // (optional) message: body, // (required) - }); - })(); + }) + })().catch(console.error) // process the notification here // required on iOS only - notification.finish(PushNotificationIOS?.FetchResult.NoData); + notification.finish(PushNotificationIOS?.FetchResult.NoData) }, // Android only - senderID: "YOUR_FIREBASE_SENDER_ID", + senderID: 'YOUR_FIREBASE_SENDER_ID', // iOS only permissions: { alert: true, @@ -67,8 +66,8 @@ function PushController({ client }: { client: Client }) { }, popInitialNotification: true, requestPermissions: true, - }); - }); - return null; + }) + }) + return null } -export default PushController; +export default PushController diff --git a/example/yarn.lock b/example/yarn.lock index 85f443f16..97e7bae0a 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -5526,6 +5526,13 @@ resolved "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-11.2.1.tgz" integrity sha512-n9kgmH7vLaU7Cdo8vGfJGGwhrlgppaOSq5zKj9I7H4k5iRM3aNtwURw83mgrc22Ip7nSye2afZV2xDiIyvHttQ== +"@react-native-community/push-notification-ios@^1.11.0": + version "1.11.0" + resolved "https://registry.yarnpkg.com/@react-native-community/push-notification-ios/-/push-notification-ios-1.11.0.tgz#d8ec4acfb52260cb779ed0379b9e197db7841b83" + integrity sha512-nfkUs8P2FeydOCR4r7BNmtGxAxI22YuGP6RmqWt6c8EEMUpqvIhNKWkRSFF3pHjkgJk2tpRb9wQhbezsqTyBvA== + dependencies: + invariant "^2.2.4" + "@react-native/assets@1.0.0": version "1.0.0" resolved "https://registry.npmjs.org/@react-native/assets/-/assets-1.0.0.tgz" @@ -13538,6 +13545,11 @@ react-native-modal@^13.0.1: prop-types "^15.6.2" react-native-animatable "1.3.3" +react-native-push-notification@^8.1.1: + version "8.1.1" + resolved "https://registry.yarnpkg.com/react-native-push-notification/-/react-native-push-notification-8.1.1.tgz#a41d20c70ea5a7709417e96261b225461f8dc73a" + integrity sha512-XpBtG/w+a6WXTxu6l1dNYyTiHnbgnvjoc3KxPTxYkaIABRmvuJZkFxqruyGvfCw7ELAlZEAJO+dthdTabCe1XA== + react-native-qrcode-svg@6.2.0: version "6.2.0" resolved "https://registry.npmjs.org/react-native-qrcode-svg/-/react-native-qrcode-svg-6.2.0.tgz"