Latest update: December 2013
                            In this tutorial, we'll show you how to use PhotoShare!
                                
 We'll be making use of the
                                Enable Photo Share mode and
                                Disable Photo Share mode commands to do
                                this (from
                                command.cgi). This tutorial builds off of
                                iOS Tutorial 7: Uploading to FlashAir.
                        
With PhotoShare mode, we can publicly share files from a specific directory. Using it, our application is able to share the images and dates we choose.
Note: We recommend that you use a different SSID for PhotoShare. By default all images on your FlashAir will be available to the public once PhotoShare is disabled; however, if you switch back to the original SSID it will be forced to stop sharing. For information about how to change your cards SSID, see iOS Tutorial 6: Changing SSID and Network Password.
Here's the screen layout of our app:
 
                        First, we'll add screen 5:"PhotoShare Active Screen" to iOS Tutorial 7: Uploading to FlashAir.
Next we'll be adding a Photoshare button to Screen 4 (the "Operation Screen").
When the user taps on an item, Screen 5(the "PhotoShare Active Screen") will be displayed.
First, lets add the "PhotoShare" button and behavior (to iOS Tutorial 7: Uploading to FlashAir).
We will be using
                            command.cgi's op 200 to enable PhotoShare. 
command.cgi with
                                op=200, folder path, and date
                                http://flashair/command.cgi?op=200&DIR=/DCIM/100__TSB&DATE=17153
                                    OK If we successfully enabled PhotoShare mode.
                                            400 Bad Request If something went wrong.
                                            Enabling PhotoShare.
- (IBAction) photoshareButton:(id)sender {
    NSError *error = nil;
    // Set photoshare
    // Make url
    NSString *urlStr = [@"http://flashair/command.cgi?op=200&DIR="
                                                         stringByAppendingString:self.path ];
    urlStr = [urlStr stringByAppendingString:@"&DATE="];
    urlStr = [urlStr stringByAppendingString: [self getDate16: self.date]];
    NSURL *url = [NSURL URLWithString:urlStr];
    //Run cgi
    NSString *rtnStr = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding
                                                                                 error:&error];
    if ([error.domain isEqualToString:NSCocoaErrorDomain]) {
        NSLog(@"command.cgi %@\n", error);
    } else {
        if ([rtnStr isEqualToString:@"OK"]) {
            // Segue
            [self performSegueWithIdentifier:@"toPhotoshare" sender:self];
        } else {
            NSLog(@"%@", rtnStr);
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PhotoShare" message:@"
               command.cgi failed" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert show];
            return;
        }
    }
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Pass next View the Data
    if ([segue.identifier isEqualToString:@"toImageView"]) {
        FSImageViewController *imageViewController = segue.destinationViewController;
        imageViewController.fileInfo = rowdata;
    }
    if ([segue.identifier isEqualToString:@"toPhotoshare"]) {
        FSPhotoShareViewController *photoShareViewController = segue.destinationViewController;
        photoShareViewController.path = [self.path stringByAppendingString:@"/"];
        photoShareViewController.date = self.date;
    }
}
This screen will be active after the user enable PhotoShare. When the user hits back, we'll disable PhotoShare and alert the user.
We will be using
                            command.cgi's op 201 to disable PhotoShare. 
command.cgi with
                                op=201
                                http://flashair/command.cgi?op=201
                                    OK If we've successfully disabled PhotoShare mode.
                                            400 Bad Request If something went wrong.
                                            - (IBAction)backButton:(id)sender {
    // back button was pressed.
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PhotoShare" message:
        @"Do you disable PhotoShare?" delegate:self cancelButtonTitle:@"Cancel"
                                                 otherButtonTitles:@"OK", nil];
    [alert show];
}
- (void) disablePhotoShare {
    // Disable photoshare
    // Make url
    NSError *error;
    NSString *urlStr = @"http://flashair/command.cgi?op=201";
    NSURL *url = [NSURL URLWithString:urlStr];
    //Run cgi
    NSString *rtnStr = [NSString stringWithContentsOfURL:url encoding:
                                            NSUTF8StringEncoding error:&error];
    if ([error.domain isEqualToString:NSCocoaErrorDomain]) {
        NSLog(@"command.cgi %@\n", error);
    } else {
        if ([rtnStr isEqualToString:@"OK"]) {
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            NSLog(@"%@", rtnStr);            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"PhotoShare" 
                message:@"command.cgi failed" delegate:nil cancelButtonTitle:nil
                                                 otherButtonTitles:@"OK", nil];
            [alert show];
            return;
        }
    }
}
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (buttonIndex) {
        case 1:
            [self disablePhotoShare];
            break;
        default:
            break;
    }
}
Let's enable PhotoShare!
We will disable it first before testing.
 
                        Tap the Date List button.
 
                        Try to select 2013/03/03.
 
                        Tap the PhotoShare button and set up PhotoShare.
 
                        Success to enable PhotoShare and translate to the PhotoShare Active Screen.
 
                        Confirm PhotoShare.
                            
 Only the images in the specified folder and date are displayed.
 
                        ios_tutorial_08.zip (63KB)
All sample code on this page is licensed under BSD 2-Clause License