我想将用户统计信息添加到我的应用中。 我喜欢将iOS版本和iDevice模型转换为我服务器上的.csv文件。我知道如何获取iOS版本和型号名称,但不知道如何将数据写入.csv文件
获取iOS版本:[UIDevice currentDevice]. systemVersion;
获取型号名称:[UIDevice currentDevice]. model;
是否有人知道如何将iOS系统版本编写为csv文件,如下所示:
iPhone,6.1
iPad,5.1
iPod,4.3
这是我现在使用的代码,但字符串未写入.csv文件:
NSString *userinfopath = @"http://idoodler.de/userdata.csv";
NSURL *userinfo = [NSURL URLWithString:userinfopath];
if (![[NSFileManager defaultManager] fileExistsAtPath:userinfopath]) {
[[NSFileManager defaultManager] createFileAtPath: userinfopath contents:nil attributes:nil];
NSLog(@"Route creato");
}
NSMutableString *writeString = [NSMutableString stringWithFormat:@"%@ ,%@",[UIDevice currentDevice]. model,[UIDevice currentDevice]. systemVersion];
NSLog(@"writeString :%@",writeString);
NSFileHandle *handle;
handle = [NSFileHandle fileHandleForWritingAtPath: userinfopath ];
//say to handle where's the file fo write
[handle truncateFileAtOffset:[handle seekToEndOfFile]];
//position handle cursor to the end of file
[handle writeData:[writeString dataUsingEncoding:NSUTF8StringEncoding]];
答案 0 :(得分:0)
使用此代码
- (IBAction)saveAsFileAction:(id)sender {
if (![[NSFileManager defaultManager] fileExistsAtPath:[self dataFilePath]]) {
[[NSFileManager defaultManager] createFileAtPath: [self dataFilePath] contents:nil attributes:nil];
NSLog(@"Route creato");
}
NSMutableString *writeString = [NSMutableString stringWithFormat:@"%@ ,%@",[UIDevice currentDevice]. model,[UIDevice currentDevice]. systemVersion];
NSLog(@"writeString :%@",writeString);
NSFileHandle *handle;
handle = [NSFileHandle fileHandleForWritingAtPath: [self dataFilePath] ];
//say to handle where's the file fo write
[handle truncateFileAtOffset:[handle seekToEndOfFile]];
//position handle cursor to the end of file
[handle writeData:[writeString dataUsingEncoding:NSUTF8StringEncoding]];
}