Translate

Monday, July 9, 2012

Write bundle version in Plist file


-(void)createVersionPList{
    NSString *mWritablePath;
    NSData *plistData1;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    BOOL success;
    
    NSString *plistDirectory = [NSString stringWithFormat:@"%@/library",[DocumentDirectory libraryDirectoryPath]];
    
    mWritablePath = [plistDirectory stringByAppendingPathComponent:@"Version.plist"];
   
    success = [fileManager fileExistsAtPath:mWritablePath];
    if(success)
    {
//        NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:mWritablePath];
//        if ([[dic objectForKey:@"version"] isEqualToString:[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"]]) {
//            return;
//        }
//        else
//        {
//            NSDictionary *ducValue = [NSDictionary dictionaryWithObject:[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"] forKey:@"version"];
//            plistData1 = [NSPropertyListSerialization dataFromPropertyList:ducValue
//                                                                            format:NSPropertyListXMLFormat_v1_0 errorDescription:nil]; 
//            [plistData1 writeToFile:mWritablePath atomically:YES];
//        }
        return;
    }
    else
    {
        NSDictionary *ducValue = [NSDictionary dictionaryWithObject:[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"] forKey:@"version"];
        plistData1 = [NSPropertyListSerialization dataFromPropertyList:ducValue
                                                                        format:NSPropertyListXMLFormat_v1_0 errorDescription:nil]; 
        [plistData1 writeToFile:mWritablePath atomically:YES];
    }
}

No comments:

Post a Comment