gokadzev / capacitor-music-controls-plugin-new

An update to Cordova Music Controls plugin to support Capacitor 3
9 stars 4 forks source link

Fatal error: Unexpectedly found nil while unwrapping an Optional value #9

Closed sanderschnydrig closed 2 years ago

sanderschnydrig commented 2 years ago

Running the app on an iPhone 5s simulator with iOS 12.4 produces the following runtime error in Xcode:

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file CapacitorMusicControlsPluginNew/Plugin.swift, line 175
2022-07-11 13:29:20.835727+0200 App[75764:805906] Fatal error: Unexpectedly found nil while unwrapping an Optional value: file CapacitorMusicControlsPluginNew/Plugin.swift, line 175

concerning the following Code:

if(urlPath != nil && defaultManager.fileExists(atPath: urlPath!)){
    coverImage = UIImage(contentsOfFile: urlPath!)! // <- issue is this null-safety operator on UIImage()
} else {
    coverImage = nil;
}

I guess iPhones of older architecture are handling null safety differently or not at all. Is there a way to handle this without the app crashing?

sanderschnydrig commented 2 years ago

I know nothing about Swift but some things about null safety.

Changing this line to the following resolved the crash for me:

coverImage = UIImage(contentsOfFile: urlPath!) ?? UIImage();
gokadzev commented 2 years ago

I know nothing about Swift but some things about null safety.

Changing this line to the following resolved the crash for me:

coverImage = UIImage(contentsOfFile: urlPath!) ?? UIImage();

i'm not able to test plugin on ios so i will make blind push with your information.