1+ const isIOS = typeof cordova !== "undefined" && cordova . platformId === "ios" ;
2+ const actionMap = {
3+ "create directory" : "createDir" ,
4+ "create file" : "createFile" ,
5+ "open document file" : "openDocumentFile" ,
6+ "get image" : "getImage" ,
7+ "list volumes" : "listStorages" ,
8+ "storage permission" : "getStorageAccessPermission" ,
9+ "list directory" : "listDir" ,
10+ "format uri" : "formatUri" ,
11+ "get path" : "getPath" ,
12+ "watch file" : "watchFile" ,
13+ "unwatch file" : "unwatchFile" ,
14+ "list encodings" : "listEncodings"
15+ } ;
16+ const action = ( name ) => ( isIOS && actionMap [ name ] ) ? actionMap [ name ] : name ;
17+
118module . exports = {
219 copy : function ( srcPathname , destPathname , onSuccess , onFail ) {
320 cordova . exec ( onSuccess , onFail , 'SDcard' , 'copy' , [ srcPathname , destPathname ] ) ;
421 } ,
522 createDir : function ( pathname , dir , onSuccess , onFail ) {
6- cordova . exec ( onSuccess , onFail , 'SDcard' , 'create directory' , [ pathname , dir ] ) ;
23+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'create directory' ) , [ pathname , dir ] ) ;
724 } ,
825 createFile : function ( pathname , file , onSuccess , onFail ) {
9- cordova . exec ( onSuccess , onFail , 'SDcard' , 'create file' , [ pathname , file ] ) ;
26+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'create file' ) , [ pathname , file ] ) ;
1027 } ,
1128 delete : function ( pathname , onSuccess , onFail ) {
1229 cordova . exec ( onSuccess , onFail , 'SDcard' , 'delete' , [ pathname ] ) ;
@@ -15,28 +32,28 @@ module.exports = {
1532 cordova . exec ( onSuccess , onFail , 'SDcard' , 'exists' , [ pathName ] ) ;
1633 } ,
1734 formatUri : function ( pathName , onSuccess , onFail ) {
18- cordova . exec ( onSuccess , onFail , 'SDcard' , 'format uri' , [ pathName ] ) ;
35+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'format uri' ) , [ pathName ] ) ;
1936 } ,
2037 getPath : function ( uri , filename , onSuccess , onFail ) {
21- cordova . exec ( onSuccess , onFail , 'SDcard' , 'get path' , [ uri , filename ] ) ;
38+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'get path' ) , [ uri , filename ] ) ;
2239 } ,
2340 getStorageAccessPermission : function ( uuid , onSuccess , onFail ) {
24- cordova . exec ( onSuccess , onFail , 'SDcard' , 'storage permission' , [ uuid ] ) ;
41+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'storage permission' ) , [ uuid ] ) ;
2542 } ,
2643 listStorages : function ( onSuccess , onFail ) {
27- cordova . exec ( onSuccess , onFail , 'SDcard' , 'list volumes' , [ ] ) ;
44+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'list volumes' ) , [ ] ) ;
2845 } ,
2946 listDir : function ( src , onSuccess , onFail ) {
30- cordova . exec ( onSuccess , onFail , 'SDcard' , 'list directory' , [ src ] ) ;
47+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'list directory' ) , [ src ] ) ;
3148 } ,
3249 move : function ( srcPathname , destPathname , onSuccess , onFail ) {
3350 cordova . exec ( onSuccess , onFail , 'SDcard' , 'move' , [ srcPathname , destPathname ] ) ;
3451 } ,
3552 openDocumentFile : function ( onSuccess , onFail , mimeType ) {
36- cordova . exec ( onSuccess , onFail , 'SDcard' , 'open document file' , mimeType ? [ mimeType ] : [ ] ) ;
53+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'open document file' ) , mimeType ? [ mimeType ] : [ ] ) ;
3754 } ,
3855 getImage : function ( onSuccess , onFail , mimeType ) {
39- cordova . exec ( onSuccess , onFail , 'SDcard' , 'get image' , mimeType ? [ mimeType ] : [ ] ) ;
56+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'get image' ) , mimeType ? [ mimeType ] : [ ] ) ;
4057 } ,
4158 rename : function ( pathname , newFilename , onSuccess , onFail ) {
4259 cordova . exec ( onSuccess , onFail , 'SDcard' , 'rename' , [ pathname , newFilename ] ) ;
@@ -53,14 +70,14 @@ module.exports = {
5370 } ,
5471 watchFile : function ( filename , listener , onFail ) {
5572 var id = parseInt ( Date . now ( ) + Math . random ( ) * 1000000 ) + '' ;
56- cordova . exec ( listener , onFail , 'SDcard' , 'watch file' , [ filename , id ] ) ;
73+ cordova . exec ( listener , onFail , 'SDcard' , action ( 'watch file' ) , [ filename , id ] ) ;
5774 return {
5875 unwatch : function ( ) {
59- cordova . exec ( null , null , 'SDcard' , 'unwatch file' , [ id ] ) ;
76+ cordova . exec ( null , null , 'SDcard' , action ( 'unwatch file' ) , [ id ] ) ;
6077 }
6178 } ;
6279 } ,
6380 listEncodings : function ( onSuccess , onFail ) {
64- cordova . exec ( onSuccess , onFail , 'SDcard' , 'list encodings' , [ ] ) ;
81+ cordova . exec ( onSuccess , onFail , 'SDcard' , action ( 'list encodings' ) , [ ] ) ;
6582 }
66- } ;
83+ } ;
0 commit comments