user760500
user760500

Reputation: 11

iphone picking file from desktop

I am a beginner in objective c and iphone programming. I'm making a program for transfering files from iphone to server through gprs. I dont know that how can i pick a file from the desktop to load into the simulator and then sending the file to the server.please explain that how can i pick such file and i also dont know how to access the path of a file in a mac operating system. Can the following code be useful in picking up a file

NSString *urlStr = @"192.168.178.26";
    if (![urlStr isEqualToString:@""]) {
        NSURL *website = [NSURL URLWithString:urlStr];
        if (!website) {
            NSLog(@"%@ is not a valid URL");
            return;
        }
    NSHost *host = [NSHost hostWithName:[website host]];
        [NSStream getStreamsToHost:host port:3258 inputStream:&iStream  outputStream:&oStream];
        [iStream retain];
        [oStream retain];
        [iStream setDelegate:self];
        [oStream setDelegate:self];
        [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
                           forMode:NSDefaultRunLoopMode];
        [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop]
                           forMode:NSDefaultRunLoopMode];
        [iStream open];
        [oStream open];

Upvotes: 0

Views: 157

Answers (2)

Black Frog
Black Frog

Reputation: 11703

You can add your test file to the project as a resource.

Upvotes: 0

Tyler Zale
Tyler Zale

Reputation: 634

You will need to look at using Documents path and saving items into the phone/simulators app documents folder (ios does not support user created subfolders so the hierarchies are pretty flat, exceptions being there are a few predefined places on the ios you can put files)

Examples below read/write to ios file system. You would need to transport that somehow client/server.

//ensure whatever object you pass in has the writeToFile method or this will crash. UIImage need to use UIImagePNGRepresentation or similar.
+ (void)writeToFile:(id)object withFileName:(NSString*)filename
{
    [object writeToFile:[[MyAppDelegate DocumentsPath] stringByAppendingPathComponent:filename] atomically:TRUE];
}

+ (NSData*)readFromFile:(NSString*)filename
{
    NSString* path = [[MyAppDelegate DocumentsPath] stringByAppendingPathComponent:filename];

    if ([[NSFileManager defaultManager] fileExistsAtPath:path])
    {
        return [NSData dataWithContentsOfFile:path];
    }

    return nil;
}

Upvotes: 1

Related Questions