Notification Schedule.at() results in crash on iOS [bug]
Describe the bug
Let me know if this is the wrong place--I couldn't find the Issues tab on the notification plugin repo. When attempting to schedule a Notification on iOS, the app crashes and this happens:
Jul 22 10:10:38 Task Manager (DEV)(UserNotifications)[28037] <Notice>: [------] Adding notification request 6CEA-456B to destinations: Default
Jul 22 10:10:38 Task Manager (DEV)(CoreFoundation)[28037] <Notice>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '__SwiftValue').'
*** First throw call stack:
(0x1a2bf8f20 0x19aa8a018 0x1a1a2adf4 0x1a1a29ba4 0x1a1a29324 0x1a1a48780 0x1a1a29574 0x1ca838408 0x1a1a29574 0x1ca82996c 0x1a1a29574 0x1a1a4b5ac 0x1a1a4b3a8 0x1a1a83c4c 0x1a1afc15c 0x1a1afbdec 0x1ca83d5d8 0x1aaa9ddd4 0x1aaaad2c4 0x1ca83d45c 0x1ca83b7c0 0x1016041c4 0x1016090e4 0x101609448 0x1015e6ce4 0x1015e8a48 0x1a14e8068 0x1015e64d4 0x1015e6d30 0x1aaa9c13c 0x1aaa9ddd4 0x1aaaa5400 0x1aaaa5f30 0x1aaab0cb4 0x1aaab0528 0x1ffa4f934 0x1ffa4c0cc)
Xcode tells me the error is being thrown on line 113 of NotificationPlugin.swift Thanks!
Reproduction
import { isPermissionGranted, requestPermission, Schedule, sendNotification } from '@tauri-apps/plugin-notification'
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
if (permissionGranted) {
sendNotification({
title: "test",
body: "test",
schedule: Schedule.at(new Date())
})
}
I've tried later dates, too, of course.
Expected behavior
No response
Full tauri info output
[✔] Environment
- OS: Mac OS 14.1.0 X64
✔ Xcode Command Line Tools: installed
✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
✔ rustup: 1.24.3 (2021-05-31)
✔ Rust toolchain: stable-aarch64-apple-darwin (default)
- node: 20.13.1
- npm: 10.5.2
[-] Packages
- tauri [RUST]: 2.0.0-beta.24
- tauri-build [RUST]: 2.0.0-beta.19
- wry [RUST]: 0.41.0
- tao [RUST]: 0.28.1
- @tauri-apps/api [NPM]: 2.0.0-beta.13
- @tauri-apps/cli [NPM]: 2.0.0-beta.20
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ["../dist","../src/styles/themes","../src/tabs","../src/fonts"]
- devUrl: http://localhost:1420/
- bundler: Vite
[-] iOS
- Developer Teams: -----
Stack trace
No response
Additional context
No response
I'm also hitting this issue on iOS 18.1
Here is the exception reported in xcode:
Exception NSException * "*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '__SwiftValue')." 0x0000600000c9dbf0
It looks like it could be from the schedule object added to userInfo here: https://github.com/tauri-apps/tauri-plugin-notification/blob/0cabfe5eddb7b99056d4241394d7a5ced1ee9379/ios/Sources/Notification.swift#L43
From the Swift documentation it looks like the object needs to conform to the property-list format. Though i'm not a swift developer and have no clue 😅
Repro code:
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === "granted";
}
if (permissionGranted) {
sendNotification({
title: "Tauri",
body: "Tauri is awesome!",
schedule: Schedule.at(add(new Date(), { seconds: 30 }), false, true),
});
}
[✔] Environment
- OS: Mac OS 15.0.1 arm64 (X64)
✔ Xcode Command Line Tools: installed
✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
✔ Rust toolchain: stable-aarch64-apple-darwin (default)
- node: 21.5.0
- pnpm: 9.9.0
- npm: 10.2.4
[-] Packages
- tauri 🦀: 2.0.6
- tauri-build 🦀: 2.0.2
- wry 🦀: 0.46.3
- tao 🦀: 0.30.5
- @tauri-apps/api : 2.0.3
- @tauri-apps/cli : 2.0.5
[-] Plugins
- tauri-plugin-store 🦀: 2.1.0
- @tauri-apps/plugin-store : 2.1.0
- tauri-plugin-shell 🦀: 2.0.2
- @tauri-apps/plugin-shell : 2.0.1
- tauri-plugin-notification 🦀: 2.0.1
- @tauri-apps/plugin-notification : 2.0.0
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- framework: React
- bundler: Webpack
@monsieurjonees, were you able to find any workaround?
I'm having this issue as well. It seems to be with any argument passed to the schedule property
Similar problem:
Thread 9 Crashed:: Dispatch queue: com.apple.usernotifications.UNUserNotificationServiceConnection
0 libunwind.dylib 0x7ffa16939fbf _Unwind_RaiseException + 399
1 libc++abi.dylib 0x7ff801bf48fc __cxa_rethrow + 78
2 libobjc.A.dylib 0x7ff8019be8dc objc_exception_rethrow + 37
3 Foundation 0x7ff8029ee8a9 _NSXPCDistantObjectSimpleMessageSend3 + 107
4 UserNotifications 0x7ff80ec67233 __104-[UNUserNotificationServiceConnection addNotificationRequest:forBundleIdentifier:withCompletionHandler:]_block_invoke + 294
5 libdispatch.dylib 0x7ff801ac65b6 _dispatch_client_callout + 6
6 libdispatch.dylib 0x7ff801abc745 _dispatch_lane_barrier_sync_invoke_and_complete + 92
7 UserNotifications 0x7ff80ec670a5 -[UNUserNotificationServiceConnection addNotificationRequest:forBundleIdentifier:withCompletionHandler:] + 725
8 UserNotifications 0x7ff80ec63238 -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:] + 220
Are there any plans to fix this error?