Blog > Komentarze do wpisu
Importing CSV data file into an iOS app via email attachment - Part 2 [English]
In my previous post I've explained in details how to implement data import into an iOS app via email attachment. There is one small thing... ok, two small things I still want to mention. Click ...CZYTAJ DALEJ... below to read on.

 

In my previous post  I've explained in details how to implement data import into an iOS app via email attachment.



There is one small thing... ok, two small things I still want to mention.

 

 

>>> START HERE <<

 



- 1 -



It is possible, especially in case of widely used CSV file format that more than one application can handle it.



Take a look at screenshots below:

    Importing CSV data file into an iOS app via email attachment       Importing CSV data file into an iOS app via email attachment   
Figure 1 Figure 2

 

The fig. 1 shows what happens if more than one application supports the same file format. What we see here is an additional option to chose from “Open In…”, when selected, the default/first action sheet (fig. 1) will be replaced with a different one (fig. 2) displaying all applications that can handle selected file format (CSV in this case).



Note. The default/first action sheet (fig. 1) always shows the last application used to open a particular file format.



It is always worth considering using an app specific file extension.



Also, the fact that all three apps shown above Eco Drive, Eco Drive Lite and US Presidents support CSV files doesn’t necessary mean we can throw any comma separated values at them. All mentioned apps are parsing CSV values correctly however the final import results are not what we expect.



The screenshot below shows what happens when we try to import the Eco Drive CSV data file into the US Presidents app.


Importing CSV data file into an iOS app via email attachment
 

When, on the other hand we try to import the US Presidents.csv file into the Eco Drive app - nothing happens.



- 2 -



The solution shown in part 1  of the tutorial uses application didFinishLaunchingWithOptions: method in application delegate to handle the file. If we try to import a large file this way our app can be killed by iOS as we have limited time to execute code within this method. It’s approximately 5 seconds. It may be worth considering moving the import to another thread or at least run it with a delay using performSelector method:

NSURL *url = (NSURL *)[launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
if (url != nil && [url isFileURL]) {
    //[self handleOpenURL:url];
    [self performSelector:@selector(handleOpenURL:) withObject:url afterDelay:60];   
}

 

I’m working on an iOS app that will have to offer data import for large CSV files (5MB+ each) and plan to share my experiences on this later.


środa, 21 grudnia 2011, m0rt1m3r

Related Posts Plugin for WordPress, Blogger...

Polecane wpisy

Komentarze
2012/09/14 13:42:13
Hi,
This is a great walkthrough and great sample code. With regard to the last part - large datasets - it may not be a timing issue only. I tried it with an 8 column dataset consisting of 1050 rows and the alloc profiler shows that memory usage at csv file import peaks at 260MB. Amazingly, it still worked well on iPhone 4S and iPad3, provided the app was already running when the csv was downloaded. If I kill the app and delete it from the background and then import the csv at launch, the iPhone gives up... One of the reasons for this may be the fact that the president object instants are all created directly in the initial loop at launch. This, I think, is not necessary. Parsing the rows into an (ivar) array of NSStrings initially and then creating arrays from those strings in the row for indexPath removes the need for individual objects altogether, apart from the NSMutableArray that holds the rows, of course. This does not require a background thread and is quite easy to set up. It decreases the memory footprint tremendously, alloc profiler now showed give or take 2MB at launch peak. The csv file itself, by the way, is 190KB. Do let me know if you'd like to see the code I used for the above approach. It also has the TableViewController set up as a NavigationController's rootVC, so that users can tap rows and see more detail. Yours helped me so much, I'd be happy to return the favor.
Best regards,
Diederik Meijer
-
2012/09/16 05:23:01
Thank you for your comment.

Please send me your solution. I'll take a look and most likely update the post. You can send me your sample code to notatkiprogramisty [at] gmail.com or spritebandits [at] gmail.com.

Best regards,
Damian




PowerBuilder Tetris
D - Tetris



Programowanie iOS

C# ToolBox

SQL / TSQL / PLSQL ToolBox

Linux / Unix ToolBox





Zaprzyjaznione Strony

Sprite Bandits

Cake Time