Showing posts with label NSURL. Show all posts
Showing posts with label NSURL. Show all posts

Sunday, December 22, 2013

Get file name and extension from URL path

How to get file name with extension in a URL path is relatively straight forward in iOS. 

The code below should work. Put your url into a NSURL variable named yourURL or whatever. Then type the below:

 NSString *JPEGfilename = [[yourURL absoluteString] lastPathComponent];

This will give you your JPEG filename or below:

 NSURL *yourURL = [NSURL urlWithString:@"http://www.hdwallpapers.in/walls/honda_v4_concept_widescreen_bike-wide.jpg"];
 NSString *JPEGfilename = [yourURL lastPathComponent];

Friday, August 30, 2013

Downloading Content to Local iOS Documents Directory

This example shows you how to download a remote file into an iOS Documents Directory from your iOS device. This is helpful for updates, and persisting data into your application, to replace static data. This allows you to keep your data fresh and dynamic.

- (void) downloadNewContent {
    NSLog(@"Downloading New Content...");
    NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"/temp"];
    NSError *error = nil;
    if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
        [[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];
    
    NSURL *url = [NSURL URLWithString:@"http://naep-sp2010dev.naepims.org:8889/update.zip"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    if(data) {
        stringPath = [stringPath stringByAppendingPathComponent:[url lastPathComponent]];
        [data writeToFile:stringPath atomically:YES];
    }
    

}

Generating "Always On Top" NSWindow in macOS across all detected displays

Also: Using UIKit & Cocoa Frameworks using Objective-C In m acOS or OS X , written in either Objective-C or Swift  Langues, you m...