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

macOS notification crash #1507

Closed
hongfeiyang opened this issue Feb 27, 2022 · 4 comments · Fixed by #1510
Closed

macOS notification crash #1507

hongfeiyang opened this issue Feb 27, 2022 · 4 comments · Fixed by #1510

Comments

@hongfeiyang
Copy link

hongfeiyang commented Feb 27, 2022

Describe the bug
application crashed when requesting macOS notification permission with error Could not cast value of type 'NSNull' (0x7ff84f13f710) to 'NSNumber' (0x7ff84f13ed78).

I also could not get the macOS notification permission request to work with the sample code, I understand that there are some additional setup, but all I found are for other platforms but not macOS, so I assume that macOS don't need any additional setup like changing things in info.plist or adding some initialisation code in AppDelegate.swift. After comparing the sample code macOS folder with my own, the only difference I can tell is that I don't have SandBox enabled. Is there anything additional I should do to get macOS notification working?

To Reproduce

    flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            IOSFlutterLocalNotificationsPlugin>()
        ?.requestPermissions(
          alert: true,
          badge: true,
          sound: true,
        );
    final result = await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            MacOSFlutterLocalNotificationsPlugin>()
        ?.requestPermissions();
    print('request permission: $result');

use the example project in this repository, but remove the optional parameters when calling requestPermissions, the application will crash with error:
Could not cast value of type 'NSNull' (0x7ff84f13f710) to 'NSNumber' (0x7ff84f13ed78).

Expected behavior

should not crash

Sample code to reproduce the problem

@MaikuB
Copy link
Owner

MaikuB commented Feb 28, 2022

Thanks for spotting this. The issue is the parameters should've defaulted to true and also had been non-nullable on macOS but is nullable (note: they're non-nullable on macOS). I would suggest you explicitly specify the permissions you need on macOS as attempt to make some changes to the method signature etc is a breaking change so will be part of the 10.0.0 (pre)release that's currently being worked on

@MaikuB
Copy link
Owner

MaikuB commented Feb 28, 2022

Actually what I could do is put some coalescing code on the macOS/Swift side for a 9.3.3 release then in 10.0.0 is where there'll be a breaking change in the API signature but functionally it should behave the same

@2022zhangyuhui
Copy link

你好,flutter_local_notifications在oppoandroid 11上没有效果,通道绑定自定义铃声失败 ,能帮忙看看什么原因吗?

@hongfeiyang
Copy link
Author

你好,flutter_local_notifications在oppoandroid 11上没有效果,通道绑定自定义铃声失败 ,能帮忙看看什么原因吗?

用英文开一个新的issue 这个issue已经close了 作者也看不懂中文

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants