2013-11-04 252 views
3

我已經開發的應用程序中,我是從服務器上下載圖像和UITableView應用程序被拒絕,由於從服務器的iOS

應用遭到拒絕的原因顯示圖像的下載

In particular, we found that on launch and/or content download, your app stores 2.67 MB. To check how much data your app is storing:

The iOS Data Storage Guidelines indicate that only content that the user creates using your app, e.g., documents, new files, edits, etc., should be backed up by iCloud.

Temporary files used by your app should only be stored in the /tmp directory; please remember to delete the files stored in this location when the user exits the app.

Data that can be recreated but must persist for proper functioning of your app - or because customers expect it to be available for offline use - should be marked with the "do not back up" attribute. For NSURL objects, add the NSURLIsExcludedFromBackupKey attribute to prevent the corresponding file from being backed up. For CFURLRef objects, use the corresponding kCFURLIsExcludedFromBackupKey attribute.

這裏是我的代碼顯示我如何從服務器下載數據並顯示它:

- (BOOL)fileExist:(NSString *)name //Check's whether image Exists in Doc Dir. 
{ 
    BOOL theSuccess; 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name]; 

    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    theSuccess = [fileManager fileExistsAtPath:fullPath]; 
    if(theSuccess){ 
     return YES; 
    } else { 
     return NO; 
    } 
} 

- (void)downloadFile:(NSString *)urlFile withName:(NSString *)fileName //If image not exists it will download image. 
{ 
    NSString *trimmedString = [urlFile stringByTrimmingCharactersInSet: 
           [NSCharacterSet whitespaceAndNewlineCharacterSet]]; 
    if ([trimmedString length]>0) 
    { 
     HTTPEaterResponse *response = [HTTPEater get:[NSString stringWithFormat:@"%@",trimmedString]]; 

     if ([response isSuccessful]) 
     { 
      [self saveImage:[[UIImage alloc] initWithData:[response body]] withName:fileName]; 
     } 
    } 

} 

-(void)saveImage:(UIImage *)image withName:(NSString *)name //After downloading image it stores in Doc dir. 
{ 
    NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[@"Documents/" stringByAppendingString:name]]; 
    [UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES]; 
} 

- (UIImage *)loadImage:(NSString *)name //Used for displaying. 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name]; 
    UIImage *img = [UIImage imageWithContentsOfFile:fullPath]; 

    return img; 
} 

顯示數據的代碼:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
    { 
     ... 


    if ([dicImages valueForKey:[[msg_array objectAtIndex:indexPath.row] valueForKey:@"merchantimage"]]) 
    { 
     cell.MerchntLogo.image=[dicImages valueForKey:[[msg_array objectAtIndex:indexPath.row] valueForKey:@"merchantimage"]]; 
    } 
    else 
    { 
     if (!isDragging_msg && !isDecliring_msg) 
     { 
      if ([[[msg_array objectAtIndex:indexPath.row] valueForKey:@"merchantimage"] length]!=0) 
      { 
       [dicImages setObject:[UIImage imageNamed:@"rowDefault.png"] forKey:[[msg_array objectAtIndex:indexPath.row] valueForKey:@"merchantimage"]]; 
       [self performSelectorInBackground:@selector(downloadImage_3:) withObject:indexPath]; 
      } 
     } 
     else 
     { 
      cell.MerchntLogo.image=[UIImage imageNamed:@"rowDefault.png"]; 
     } 
    } 

... 

} 

-(void)downloadImage_3:(NSIndexPath *)path{ 

    if ([[[msg_array objectAtIndex:path.row] valueForKey:@"merchantimage"] length]!=0) 
    { 
     NSString *str=[[msg_array objectAtIndex:path.row] valueForKey:@"merchantimage"]; 

     UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str]]]; 
      [dicImages setObject:img forKey:[[msg_array objectAtIndex:path.row] valueForKey:@"merchantimage"]]; 

     [tblProdDetail performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 
    } 

} 

請幫我弄清楚爲什麼我的應用程序被拒絕,以及我能做些什麼來糾正問題。

回答

2

你需要做他們所說的。馬克文件

在didFinishLaunching

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
documentsDirectory = [paths objectAtIndex:0]; 

[self applyAttributes:documentsDirectory]; 

只需添加,然後實現此方法

#pragma mark - Application's Documents directory 

// Returns the URL to the application's Documents directory. 
- (NSURL *)applicationDocumentsDirectory 
{ 


    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; 
} 

-(void)applyAttributes:(NSString *)folderPath 
{ 
    NSArray *filesArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:folderPath error:nil]; 
    NSEnumerator *filesEnumerator = [filesArray objectEnumerator]; 
    NSString *fileName; 

    while (fileName = [filesEnumerator nextObject]) { 
    // NSLog(@"apply to %@", [[NSURL fileURLWithPath:[folderPath stringByAppendingPathComponent:fileName]] path]); 
    if([self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:[folderPath stringByAppendingPathComponent:fileName]]]) 
    { 
     //NSLog(@"success applying"); 
    } 

    //NSDictionary *fileDictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:[folderPath stringByAppendingPathComponent:fileName] error:nil]; 
    //fileSize += [fileDictionary fileSize]; 
    } 

} 



- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL 
{ 
    if([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]) 
    { 
    NSError *error = nil; 
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES] 
            forKey: NSURLIsExcludedFromBackupKey error: &error]; 
    if(!success){ 
     NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error); 
    } 
    return success; 
    } 

    return NO; 

} 
+0

從我應該在哪裏調用此方法? ' - (NSURL *)applicationDocumentsDirectory' – Krunal

1

使用此方法繞過在iCloud上

存儲數據

通行證文件路徑這種方法

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL 
    { 
     const char* filePath = [[URL path] fileSystemRepresentation]; 

     const char* attrName = "com.apple.MobileBackup"; 
     u_int8_t attrValue = 1; 

     BOOL result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); 
     return result; 
    } 
+0

我應該從哪裏調用這個方法?這條線應該保持原樣? 'const char * attrName =「com.apple.MobileBackup」;' – Krunal

+0

將文件保存到本地目錄後,我也建議您創建自己的目錄以下載並保存圖像...使用此方法創建目錄 \t \t if(![[的NSFileManager defaultManager] createDirectoryAtPath:filePathAndDirectory \t \t \t \t \t \t \t \t \t withIntermediateDirectories:否 \t \t \t \t \t \t \t \t \t \t \t \t \t \t屬性:無 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t誤差:&錯誤]) \t \t { \t \t \t的NSLog(@ 「創建目錄錯誤:%@」,錯誤); \t \t} –

3

您的應用明顯違反了Apple的數據存儲準則,該準則規定只有用戶生成的數據應存儲在Documents文件夾中。這些數據會自動備份到iCloud並與5GB上限相沖突。如果應用程序在該文件夾中存儲了太多數據(Apple認爲該數據庫),則可能會從App Store中拒絕該數據。

您的數據不會被歸類爲用戶生成的內容,並且它超過了2 MB,這是限制。

您可以通過引用來防止備份數據。

https://developer.apple.com/library/ios/qa/qa1719/_index.html

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL 
    { 
     const char* filePath = [[URL path] fileSystemRepresentation]; 

     const char* attrName = "com.apple.MobileBackup"; 
     u_int8_t attrValue = 1; 

     BOOL result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); 
     return result; 
    } 
相關問題