Skip to content

Commit

Permalink
Add error log and fixed returned object class
Browse files Browse the repository at this point in the history
  • Loading branch information
cheekiatng committed May 28, 2015
1 parent 9e452b0 commit bc86484
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
13 changes: 7 additions & 6 deletions apidoc/Titanium/Filesystem/File.yml
Expand Up @@ -191,11 +191,12 @@ methods:
- name: getProtectionKey
summary: |
Returns the protection key value of this file object. Can be one of the following
Titanium.Filesystem constants:
IOS_FILE_PROTECTION_NONE
IOS_FILE_PROTECTION_COMPLETE
IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN
IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION
constants:
Titanium.Filesystem.IOS_FILE_PROTECTION_NONE
Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE
Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN
Titanium.Filesystem.IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION
Returns `null` if there's an error.
returns:
type: String
platforms: [iphone, ipad]
Expand Down Expand Up @@ -287,7 +288,7 @@ methods:
- name: setProtectionKey
summary: Sets the protection key as an attribute to the file identified by this file object.
description: |
Returns `true` if successfully set. Otherwise `false`.
Returns `true` if successfully set. Returns `false` if failed.
returns:
type: Boolean
parameters:
Expand Down
28 changes: 10 additions & 18 deletions iphone/Classes/TiFilesystemFileProxy.m
Expand Up @@ -153,34 +153,26 @@ -(id)spaceAvailable:(id)args
return [resultDict objectForKey:NSFileSystemFreeSize];
}

-(id)getProtectionKey:(id)args
-(NSString *)getProtectionKey:(id)args
{
NSError *error = nil;
NSDictionary * resultDict = [fm attributesOfItemAtPath:path error:&error];
if (error!=nil) return NUMBOOL(NO);
NSString *obj = [resultDict objectForKey:NSFileProtectionKey];
if (obj != nil) {
if ([obj isEqualToString:NSFileProtectionNone]) {
return @"IOS_FILE_PROTECTION_NONE";
}
if ([obj isEqualToString:NSFileProtectionComplete]) {
return @"IOS_FILE_PROTECTION_COMPLETE";
}
if ([obj isEqualToString:NSFileProtectionCompleteUnlessOpen]) {
return @"IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN";
}
if ([obj isEqualToString:NSFileProtectionCompleteUntilFirstUserAuthentication]) {
return @"IOS_FILE_PROTECTION_COMPLETE_UNTIL_FIRST_USER_AUTHENTICATION";
}
if (error != nil) {
NSLog(@"[ERROR] Error getting protection key: %@", [TiUtils messageFromError:error]);
return nil;
}
return [resultDict objectForKey:NSFileProtectionKey];
}

-(id)setProtectionKey:(id)args
-(NSNumber *)setProtectionKey:(id)args
{
ENSURE_SINGLE_ARG(args, NSString);
NSError *error = nil;
BOOL result = [fm setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:args, NSFileProtectionKey, nil] ofItemAtPath:path error:&error];
if (error!=nil) return NUMBOOL(NO);
if (error != nil) {
NSLog(@"[ERROR] Error setting protection key: %@", [TiUtils messageFromError:error]);
return NUMBOOL(NO);
}
return NUMBOOL(YES);
}

Expand Down

0 comments on commit bc86484

Please sign in to comment.