2013-11-04 43 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; 
    } 
相关问题