From 2ff56e66605672f30302926d54d708cd7aafffd2 Mon Sep 17 00:00:00 2001 From: lmnbeyond Date: Mon, 29 Jul 2013 19:50:42 +0800 Subject: [PATCH] [iOS] Simplify the code in resolveLocalFileSystemURI --- src/ios/CDVFile.m | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m index c245ee360..6b2602d32 100644 --- a/src/ios/CDVFile.m +++ b/src/ios/CDVFile.m @@ -233,19 +233,14 @@ - (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command // see if exists and is file or dir BOOL bExists = [fileMgr fileExistsAtPath:path isDirectory:&isDir]; if (bExists) { - // see if it contains docs path - NSRange range = [path rangeOfString:self.appDocsPath]; + // see if it contains docs path or temp path NSString* foundFullPath = nil; - // there's probably an api or easier way to figure out the path type but I can't find it! - if ((range.location != NSNotFound) && (range.length == [self.appDocsPath length])) { + if ([path hasPrefix:self.appDocsPath]) { foundFullPath = self.appDocsPath; - } else { - // see if it contains the temp path - range = [path rangeOfString:self.appTempPath]; - if ((range.location != NSNotFound) && (range.length == [self.appTempPath length])) { - foundFullPath = self.appTempPath; - } + } else if ([path hasPrefix:self.appTempPath]) { + foundFullPath = self.appTempPath; } + if (foundFullPath == nil) { // error SECURITY_ERR - not one of the two paths types supported result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:SECURITY_ERR];