-1
+ (NSString *)getValueforLocale:(NSString*) i18nkey :(NSString*)locale{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 
    NSLog(@"paths are : %@",paths); 
    NSString *libraryDirectory = [paths objectAtIndex:0]; 
    NSLog(@"libraryDirectory : %@",libraryDirectory); 
    NSString *filePath = [libraryDirectory stringByAppendingPathComponent:@"I8nDB"]; 
    filePath = [filePath stringByAppendingPathComponent:locale]; 
    NSLog(@"file path is : %@",filePath); 
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath]; 
    if(fileExists) 
    { 
     NSDictionary *dict = [[[NSDictionary alloc] initWithContentsOfFile:filePath]autorelease]; 
     NSDictionary *resourceBundle = [[[NSDictionary alloc] init]autorelease]; 
     NSString *keyValue = [[[NSString alloc]init]autorelease]; 
     resourceBundle = [dict valueForKey:@"hash"]; 
     keyValue=[resourceBundle valueForKey:i18nkey]; 
     NSLog(@"value for %@ is(container) : %@",i18nkey,keyValue); 
     if(keyValue != nil || keyValue != NULL) 
     { 
      return keyValue; 
     } 
     else 
     { 
      NSLog(@"key not found in the container file"); 
      NSString *path = [[NSBundle mainBundle] pathForResource:@"Localizable" 
                  ofType:@"strings" 
                 inDirectory:nil 
                forLocalization:locale]; 
      NSLog(@"path for %@ is : %@",locale,path); 
      fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; 
      if(fileExists) 
      { 
       NSDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:path]autorelease]; 
       NSLog(@"value for %@ is(resources) : %@",i18nkey,[dict objectForKey:i18nkey]); 
       return [dict objectForKey:i18nkey]; 
      } 
      else 
      { 
       return NULL; 
      } 
     } 
    } 
    else 
    { 
     NSLog(@"%@ locale does not exist in container",locale); 
     NSString *path = [[NSBundle mainBundle] pathForResource:@"Localizable" 
                 ofType:@"strings" 
                inDirectory:nil 
               forLocalization:locale]; 
     NSLog(@"path for %@ in resources is : %@",locale,path); 
     fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; 
     if(fileExists) 
     { 
      NSDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:path]autorelease]; 
      NSLog(@"value for %@ is : %@",i18nkey,[dict objectForKey:i18nkey]); 
      return [dict objectForKey:i18nkey]; 
     } 
     else 
     { 
      return NULL; 
     } 
    } 
} 

Wenn wir Autorelease aus dem obigen Code entfernen, wird in iOS7 arbeiten, wenn nicht die AppApp stürzt in iOS7 aber nicht in 8 und 9 aufgrund NSDictionary Autorelease

Mein Hauptanliegen ist es abstürzt ist, warum es doesn 't Absturz in iOS8 & 9 und stürzt nur in iOS7 ist es in der Änderung im Zusammenhang mit Autorelease über diese Versionen

+0

Es ist normal, wenn der Problemcode in der iOS-Version und nicht in anderen Versionen funktioniert. Weil Apple jede Release-Note ändert. Also nur Code ohne Problem kann in allen iOS funktionieren – larva

Antwort

0

in Ihrem Code Alloc Sie nur ein Wörterbuch in

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath]; 

so braucht man nur über sie zu kümmern, ist ein weiteres Ziel von Ihnen nicht im Besitz! Sie brauchen also keine Freigabe oder Autorelease.

Try fließt Code

+ (NSString *)getValueforLocale:(NSString*) i18nkey :(NSString*)locale 
    { 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); 
     NSLog(@"paths are : %@",paths); 
     NSString *libraryDirectory = [paths objectAtIndex:0]; 
     NSLog(@"libraryDirectory : %@",libraryDirectory); 
     NSString *filePath = [libraryDirectory stringByAppendingPathComponent:@"I8nDB"]; 
     filePath = [filePath stringByAppendingPathComponent:locale]; 
     NSLog(@"file path is : %@",filePath); 
     BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filePath]; 
     if(fileExists) 
     { 
      NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath]; 
      //NSDictionary *resourceBundle = [[[NSDictionary alloc] init]autorelease]; 
      //NSString *keyValue = [[[NSString alloc]init]autorelease]; 
      NSDictionary *resourceBundle = [dict valueForKey:@"hash"]; 
      // relese dict here because not use after 
      [dict release]; 
      NSString *keyValue=[resourceBundle valueForKey:i18nkey]; 
      NSLog(@"value for %@ is(container) : %@",i18nkey,keyValue); 
      if(keyValue != nil || keyValue != NULL) 
      { 
       return keyValue; 
      } 
      else 
      { 
       NSLog(@"key not found in the container file"); 
       NSString *path = [[NSBundle mainBundle] pathForResource:@"Localizable" 
                   ofType:@"strings" 
                  inDirectory:nil 
                 forLocalization:locale]; 
       NSLog(@"path for %@ is : %@",locale,path); 
       fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; 
       if(fileExists) 
       { 
        // NSDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:path]autorelease]; 
        NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; 
        NSLog(@"value for %@ is(resources) : %@",i18nkey,[dict objectForKey:i18nkey]); 
        return [dict objectForKey:i18nkey]; 
       } 
       else 
       { 
        return NULL; 
       } 
      } 
     } 
     else 
     { 
      NSLog(@"%@ locale does not exist in container",locale); 
      NSString *path = [[NSBundle mainBundle] pathForResource:@"Localizable" 
                  ofType:@"strings" 
                 inDirectory:nil 
                forLocalization:locale]; 
      NSLog(@"path for %@ in resources is : %@",locale,path); 
      fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path]; 
      if(fileExists) 
      { 
       // NSDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:path]autorelease]; 
       NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; 
       NSLog(@"value for %@ is : %@",i18nkey,[dict objectForKey:i18nkey]); 
       return [dict objectForKey:i18nkey]; 
      } 
      else 
      { 
       return NULL; 
      } 
     } 
    } 
0

Im manuellen Referenzzählung behält und Veröffentlichungen müssen ausgeglichen werden.

In

NSDictionary *dict = [[[NSDictionary alloc] initWithContentsOfFile:filePath]autorelease]; 
NSDictionary *resourceBundle = [[[NSDictionary alloc] init]autorelease]; 

die behält und Mitteilungen sind ausgeglichen, weil alloc (zusammen mit retain, new, copy, mutableCopy) gibt eine Instanz zurückgehalten, und autorelease zählt als release.

jedoch in

NSDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:path]autorelease]; 

haben Sie eine overrelease weil Sie autorelease etwas, das Sie nicht behalten haben.

iOS-Version hat absolut nichts damit zu tun.