react-native-get-music-files icon indicating copy to clipboard operation
react-native-get-music-files copied to clipboard

Add nil checks for assetURL and other properties in TurboSongs module

Open nahooni0511 opened this issue 11 months ago • 1 comments

This commit introduces essential nil checks across the TurboSongs module to ensure stability and error handling for properties that might not always be present, such as the assetURL, title, albumTitle, and more. Notably, this update addresses a common scenario with Apple Music, where downloaded songs for offline use do not have an assetURL. By adding these checks, the module now safely handles such cases, preventing potential crashes and improving the user experience when working with local and downloaded media items. This enhancement is crucial for developers integrating with the Apple Music library, ensuring that their applications can gracefully handle a variety of media item states.

To reproduce the issue, follow these steps: Navigate to Apple Music, select a song, add it to your library, then select the song from within your library and download it for offline use. In this scenario, the song's assetURL may be absent, leading to the issue this pull request addresses.

nahooni0511 avatar Mar 10 '24 09:03 nahooni0511

hey @nahooni0511 thanks for your PR, i would like to return the complete object, even if asserUrl or any other object property is absent, so we can match the Song / Album interfaces

interface Song {
  url: string;
  title: string;
  album: string;
  artist: string;
  duration: number;
  genre: string;
  cover: string;
}

interface Album {
  url: string;
  album: string;
  artist: string;
  numberOfSongs: string;
  cover: string;
}

You could use ternary operator for such case. i.e

[songDictionary setValue:(assetURL && assetURL.absoluteString) ? [NSString stringWithString:assetURL.absoluteString] : @"" forKey:@"url"];

Thanks again.

cinder92 avatar Apr 23 '24 07:04 cinder92