0

我喜欢将用户统计信息添加到我的应用程序中。我喜欢将 iOS 版本和 iDevice 模型传输到我服务器上的 .csv 文件。我知道如何获取 iOS 版本和型号名称,但不知道如何将数据写入 .csv 文件

获取 iOS 版本:[UIDevice currentDevice]. systemVersion;

获取模型名称:[UIDevice currentDevice]. model;

有谁知道如何将 iOS 系统版本写入 csv 文件,如下所示:

苹果手机,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]];
4

1 回答 1

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]];

}
于 2013-03-26T11:28:03.053 回答