0

I like to add user statistics to my apps. I like to transfer the iOS version and the iDevice model to a .csv file on my server. I know how to get the iOS version and the model name but not how to write the data to a .csv file

get iOS version: [UIDevice currentDevice]. systemVersion;

get model name: [UIDevice currentDevice]. model;

Does any one know how to write the iOS system version to a csv file like this:

iPhone, 6.1

iPad, 5.1

iPod, 4.3

This is the code I am now using, but the String is not been written to the .csv file:

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

1 Answer 1

0

use this code

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

}
1
  • My file is stored on my server, where must I how can I replace the fileparth with the URL? Mar 26, 2013 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.