1

I am writing an application for my parent's photo booth business.

They upload all the event pictures to different Flickr photosets on their account, and on the website they have an albums page with a collection of all their events so that people from the events can go and see all their photo strips, as well as each individual picture and then download them for themselves.

Most of their traffic is from mobile devices (my brother wrote the website specifically to fit mobile device screens as well as normal computer screens just as well); however, downloading and sharing the images is easier through an app (thanks to Apple's iOS 6 UIActivityViewController and UICollectionView).

So I'm writing the app that makes it easier to view and share the pictures. I have most of it done and working great! However, it currently only supports iOS 6 and I'm trying to include iOS 5. It only supports iOS 6 because I am using a UICollectionView to display the pictures from events. However, since iOS 5 does not include collection views I use a web view of our albums web page which displays all images.

When you select an image, you can choose a size of the image to view. When you pick a size, it opens a new tab, that includes the image and two links. One to download the image, and one to close the tab. The two links are within an unordered list and each link is its own list item.

This is the link to download the image:

<a href="/downloadImage.php?link=IMG_LINK&amp;title=TITLE">Download Image</a>

And the closing tab link has a tag of:

<a href="javascript:window.close();">

I've seen that you can use the webView's delegate method shouldStartLoadWithRequest: and then:

if ([[[request URL] absoluteString] hasPrefix:@"/downloadImage.php"]) {
    UIImageWriteToSavedPhotosAlbum(imageToBeSaved, nil, nil, nil);
    return NO;
} else if ([[[request URL] absoluteString] hasPrefix:@"javascript"]) {
    [webView goBack];
    return NO;
} else { return YES; }

Which would make it do those functions when the links are clicked...right? These do not work though. And I'm not sure how to make them work.
I am searching for the correct way to use this method, or some alternative method, if possible, to use Objective-C to do the equivalent of what the html normally does.

4

1 回答 1

0

我想出了一种方法来做我想做的事情。当您选择图像大小时,而不是让 webView 打开一个新页面。我将大小链接设置为使用以下代码直接下载图像:


// for links thats contain the displayImage.php do not allow user interaction
if ([[[request URL] absoluteString] hasPrefix:@"http://www.remembermephotobooths.com/displayImage.php?link="]) {
        //scan through the link url get the image link so that I can download it
        NSMutableArray *substring = [NSMutableArray new];
        NSScanner *scanner = [NSScanner scannerWithString:[[request URL] absoluteString]];
        [scanner scanUpToString:@"http://farm9" intoString:nil]; // Scan all characters after and including http://farm9 because all download links begin with http://farm9
        while(![scanner isAtEnd]) {
            NSString *string = nil;
            [scanner scanString:@"&title=" intoString:nil]; // Scan up to &title
            if([scanner scanUpToString:@"&" intoString:&string]) {
                [substring addObject:string];
            }
            [scanner scanUpToString:@".jpg" intoString:nil]; // Scan all characters up to and including .jpg because all images are jpegs
        }
        // save image to photo library
        UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:substring[0]]]], nil, nil, nil);
        // let the user know the image was saved
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [hud setMode:MBProgressHUDModeText];
        hud.labelText = @"Saved Image!";
        [hud setMinShowTime:1.5];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        [substring release];
        return NO; //this is what disables the links usual code and has it run my code instead
    }
    else { //all other links are enabled
        return YES;
    }
于 2012-12-18T18:54:21.023 回答