how to extract data i an Nsmutablearray to my mac ?

Discussion in 'iOS Programming' started by buldre, Jan 25, 2010.

  1. buldre macrumors newbie

    Joined:
    Jan 25, 2010
    #1
    I need to extract the data i have in my NsMutableArray so that they are readable on my mac in plain text. Im now storing accelerometer data in Nsmutablearrays which works fine, but im just wondering about the best way to "get it out from the phone" ?

    NB:

    I came accross the possibility of using FTP uploads to transfer files. However, how can i transfer the data in my arrays in such a format that i can read it in plaintext when downloaded from the FTP server?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Encode the data into a plain text file to start with and then transfer it.
     
  3. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #3
    yeah, that sounds reasonable. Im not used to working on the Iphone SDK, or any os x framework for that matter. How would you go about encoding it into a plain text file then? im used to c/c++/C# where everything i write to to is a plain textfile :p Could you hint me in the right direction?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Build an NSString containing the data. Then have a peek at the NSString Class Reference to see if there is some kind of method to write that string to a file.
     
  5. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #5
    Thank! when i write it to a file, where is it stored then?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Read the documentation I linked to. The answer is right there in the explanation of the method you're interested in.
     
  7. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #7
    thanks dude, one less problem to worry about!
     
  8. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #8
    let me refrase my question.



    ok, so i have an nsmutablearray with nsdecimalnumbers in it. What i want to do, is to build a file locally on the Iphone that is readable in plaintext, and has 1 number on each line. (this means that im going to loop through the NSMutableArray, and for each NSDecimalNumber in it, i want to have one line in the file.

    Ok, then after i have made this file, i need to get a hold of it on my mac, i.e. extract it from the iphone. I have found that one can upload to FTP server using objective-c. but i cannot understand how i do this, could someone please help me with some example code? this is very easy in C# for instance, and it is probably just as easy here, just that i dont understand how i do it.

    all help is GREATLY appreciated!!
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Here's how I would approach this part it: Create a mutable string to hold your plain text. As you loop through each element of the array, convert the number into a string and append that onto the mutable string, along with a line feed character. When the loop is done you should have a string that can be converted to an NSData for file writing.

    Concern: what are you going to do with this file once it's on the server? If you plan to parse it, you may want to put the data into some kind of structured format (XML or JSON) in order to make that task easier.

    I don't believe it's gonna be that easy. You can find some advice in the CFNetwork Programming Guide, particularly the section on Working with FTP Servers.
     
  10. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  11. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #11
    I just want to upload them to the server, im not going to parse them or anything, i just need them on my computer...

    Is there an easier way to get a hold of the file? (get it from the iphone to my mac)
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    Email it to yourself?
     
  13. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #13
    hm, that may be an possibiity.. but i read that they removed this capability from the framework?

    Is there no way of just connecting my phone to my computer and then just copy it out manually?
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    Where did you read that? Because with iPhone SDK 3.0, they actually added a MessageUI framework that makes it possible to send an email without even leaving your application.

    Not without jailbreaking, no.
     
  15. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #15
    I dont quite remember where I read it. So email seems like the best option?
     
  16. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #16
    "Best" is a pretty ambiguous term. If you use email, you'll still need to view the message on your Mac and then download the content to your filesystem. If you use FTP, you can avoid those steps but then need to make sure you have an FTP server on your Mac and will need to code the FTP transfer smarts into your app. And other approaches probably have other advantages...
     
  17. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #17
    Maybe "best" was the wrong choice of word, however all the examples I can find has to send turn over the control to the mail app inside the Iphone and let the user finish the task, and then return to the original (our) app. I was looking for a way to do transfer the files in the background as you might have understood..

    Anyways, i found http://istorageapp.com/ this application which seemingly lets me browse the documents folder of each application? if i can get that working then i can just use that application on the side to transfer my files. Does anyone have some experience with this app?

    And i tried the following code, where probex is an NsMutableArray with NsdecimalNumber objects in it. All i wanted to acheive with this functoin was to make the contents of probex into a string and print it to my console. I do not get any warnings or errors, but my application terminates ungracefully and does not print the string. After some debugging it seems that it doesnt even complete the loop.

    Code:
    -(void) toFile{
    	NSString *tmp;
    	tmp = [[NSString alloc] initWithString:@""];
    	NSMutableString *storagestring;
    	storagestring = [[NSMutableString alloc] initWithString:@""];
    	
    	for(NSDecimalNumber *temp in probex){
    		tmp = [temp stringValue];
    		[storagestring appendString:tmp];
    		[storagestring appendString:@"\n"];
    	}
    
    	NSLog(@"string made from probex:\n %@", storagestring);
    
    }
    
     
  18. buldre thread starter macrumors newbie

    Joined:
    Jan 25, 2010
    #18
    I've been scowering the net but haven't found it, could you give me a hint where its at?
     
  19. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #19
    It's on your Mac.

    Open up the docs window. Type SimpleFTP into the search box. Choose Full-Text search and you'll see it.

    Also, there is a page on the developer site that has all the apple sample code where you could find it.
     

Share This Page