Saturday, May 25, 2013

UIApplication setNewsstandIconImage example in Objective C (iOS)

[UIApplication setNewsstandIconImage]

Sets the icon of a Newsstand application to an image depicting the current issue of a publication.
- (void)setNewsstandIconImage:(UIImage *)image
Parameters of [UIApplication setNewsstandIconImage]
An image to use as the icon of a Newsstand application. Pass nil to clear the currently set image and revert to the icon stored in the application bundle.
Discussion of [UIApplication setNewsstandIconImage]
The Newsstand application icon is typically downloaded from the application’s server for each issue.
Example of [UIApplication setNewsstandIconImage]
UIApplication *app = [UIApplication sharedApplication];
[app setNewsstandIconImage:[UIImage imageWithContentsOfFile:file]];
Example of [UIApplication setNewsstandIconImage]
//Finally, if the connection succeeds in downloading the request, the delegate receives the connectionDidFinishLoading: message
    - (void)connectionDidFinishDownloading:(NSURLConnection*)connection destinationURL:(NSURL*)destinationURL {

//[webView loadRequest:request];//if you wanted load the website into the webview

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

   NSString *documentsDirectory = [paths objectAtIndex:0];
    [self saveFile:@"NSIcon" ofType:@"png" fromURL:@"" inDirectory:documentsDirectory];

UIImage * newsstandImage = [self loadImage:@"NSIcon" ofType:@"png" inDirectory:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];

   UIApplication *app = [UIApplication sharedApplication];
    [app setNewsstandIconImage:newsstandImage];