Creating iOS 5 Apps Discussion > Exporting your Weight graph via iTunes
Cool expansion. You can also do PDFs. It's a little more complicated, since they can be multi-page documents, but follows the same basic pattern.
We do some similar image stuff in Chapter 8 (or whichever chapter covers the GravityScribbler project). Including some advanced settings (like adding geolocation to the picture, or rotating it).
-Rich-

thanks im still on Ch.6 with iCloud, I wanted to create multiple files (but multipage pdf sounds interesting too) with each file with that day's timestamp. But if doesnt land on this view explicitly and add / remove entries from WeightHistory i need some notification to save graph but i think its still doable

Good luck with it.
You probably only need to take a snapshot when the user enters a new weight (otherwise the data doesn't change). And the app should automatically switch to the graph view after adding a new entry. You can grab the image whenever the view is displayed (though I'd consider adding some sort of filter, so it only grabbed the image if the data actually changed, to prevent snapping multiple images when flipping back and forth between views).
-Rich-

If you want to play around with your app more here is what I did today. Very easy (admit i followed code doing google) but end result is really cool (at least for me!).
1)declare method in GraphViewController.h as
- (void) saveImageViewInPNG;
2) open GraphViewController.m and add the definition as below
- (void) saveImageViewInPNG
{
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* graphImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Create paths to output images
NSString* pngPath = [NSHomeDirectory() stringByAppendingPathComponent:FNGraph];
// Write image to PNG
[UIImagePNGRepresentation(graphImage) writeToFile:pngPath atomically:YES];
}
3) add another method in same file, actually add viewDidAppear:(BOOL)animated
- (void) viewDidAppear:(BOOL)animated
{
[self saveImageViewInPNG];
}
4) I also declare this constant at the top
static NSString* const FNGraph = @"Documents/HistoryGraph.png";
5)Open your Hear Beat-Info.plist file add the below key
"Application supports iTunes file sharing" (its boolean flag) and set value as YES.
6) Compile and run. Add/delete some weight entries. Stop your application
5) Open itunes -> your iOS Device->Apps->Health Beat will be there with new file HistoryGraph.png file in there. You can save it on your desktop!
It actually occur to mind while reading Chapter 6 on iCloud after I read about this key and so was thinking on how to use it in our application. Then rest is easy. Thanks to Google and this book!
Hope readers will find it little amusing for a minute!
thanks
g