janpio closed pull request #16: By default always first check Documents directory. URL: https://github.com/apache/cordova-plugin-media/pull/16
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/src/ios/CDVSound.m b/src/ios/CDVSound.m old mode 100644 new mode 100755 index 5364fcbb..e1964cb2 --- a/src/ios/CDVSound.m +++ b/src/ios/CDVSound.m @@ -36,25 +36,32 @@ - (NSURL*)urlForResource:(NSString*)resourcePath { NSURL* resourceURL = nil; NSString* filePath = nil; - + NSString* docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; + // first try to find HTTP:// or Documents:// resources - + if ([resourcePath hasPrefix:HTTP_SCHEME_PREFIX] || [resourcePath hasPrefix:HTTPS_SCHEME_PREFIX]) { // if it is a http url, use it NSLog(@"Will use resource '%@' from the Internet.", resourcePath); resourceURL = [NSURL URLWithString:resourcePath]; } else if ([resourcePath hasPrefix:DOCUMENTS_SCHEME_PREFIX]) { - NSString* docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; filePath = [resourcePath stringByReplacingOccurrencesOfString:DOCUMENTS_SCHEME_PREFIX withString:[NSString stringWithFormat:@"%@/", docsPath]]; NSLog(@"Will use resource '%@' from the documents folder with path = %@", resourcePath, filePath); } else { - // attempt to find file path in www directory - filePath = [self.commandDelegate pathForResource:resourcePath]; - if (filePath != nil) { - NSLog(@"Found resource '%@' in the web folder.", filePath); + // by default always first check Documents directory + NSString *resourceDocsPath = [NSString stringWithFormat:@"%@/%@", docsPath, resourcePath]; + if ([[NSFileManager defaultManager] fileExistsAtPath:resourceDocsPath]) { + filePath = resourceDocsPath; } else { - filePath = resourcePath; - NSLog(@"Will attempt to use file resource '%@'", filePath); + + // attempt to find file path in www directory + filePath = [self.commandDelegate pathForResource:resourcePath]; + if (filePath != nil) { + NSLog(@"Found resource '%@' in the web folder.", filePath); + } else { + filePath = resourcePath; + NSLog(@"Will attempt to use file resource '%@'", filePath); + } } } // check that file exists for all but HTTP_SHEME_PREFIX ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org