Skip to content

Commit 081a206

Browse files
committed
Make work with Mavericks
1 parent 1f1d79a commit 081a206

File tree

8 files changed

+67
-161
lines changed

8 files changed

+67
-161
lines changed

External/asi-http-request

Submodule asi-http-request deleted from 1a7ae81

FlickrSavr.xcodeproj/project.pbxproj

Lines changed: 17 additions & 101 deletions
Large diffs are not rendered by default.

FlickrSavr.xcodeproj/xcuserdata/alan.xcuserdatad/xcschemes/FlickrSavr.xcscheme

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0460"
3+
LastUpgradeVersion = "0610"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -39,6 +39,15 @@
3939
ignoresPersistentStateOnLaunch = "NO"
4040
debugDocumentVersioning = "YES"
4141
allowLocationSimulation = "YES">
42+
<MacroExpansion>
43+
<BuildableReference
44+
BuildableIdentifier = "primary"
45+
BlueprintIdentifier = "E7C4FB9113FF3B190003A727"
46+
BuildableName = "FlickrSavr.saver"
47+
BlueprintName = "FlickrSavr"
48+
ReferencedContainer = "container:FlickrSavr.xcodeproj">
49+
</BuildableReference>
50+
</MacroExpansion>
4251
<AdditionalOptions>
4352
</AdditionalOptions>
4453
</LaunchAction>

FlickrSavr.xcodeproj/xcuserdata/alan.xcuserdatad/xcschemes/saverTest.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0460"
3+
LastUpgradeVersion = "0610"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

FlickrSavr/AFFlickrManager.m

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#import "AFFlickrManager.h"
22
#import "AFFlickrPhoto.h"
33
#include <stdlib.h>
4-
#import "ASIHTTPRequest.h"
5-
#import "ASIDownloadCache.h"
64

75
#define API_KEY @"4a66fc1a7ab88035aabdeff1f230a971";
8-
#define API_SECRET @"11e7a25980061c0b";
96

107
@interface AFFlickrManager ()
118
@property (strong) NSMutableArray *photos;
@@ -15,13 +12,6 @@ - (void)parseJson;
1512
@implementation AFFlickrManager
1613
AF_SYNTHESIZE(photos);
1714

18-
- (void)dealloc
19-
{
20-
AF_RELEASE(photos);
21-
22-
[super dealloc];
23-
}
24-
2515
- (id)init
2616
{
2717
self = [super init];
@@ -35,29 +25,26 @@ - (id)init
3525

3626
- (void)parseJson
3727
{
38-
NSString *interestingURLstring = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&api_key=4a66fc1a7ab88035aabdeff1f230a971&format=json&nojsoncallback=1&extras=owner_name,icon_server&per_page=100"];
28+
NSString *interestingURLstring = [NSString stringWithFormat:@"https://api.flickr.com/services/rest/?method=flickr.interestingness.getList&api_key=4a66fc1a7ab88035aabdeff1f230a971&format=json&nojsoncallback=1&extras=owner_name,icon_server&per_page=100"];
3929
NSURL *interestingURL = [NSURL URLWithString:interestingURLstring];
40-
ASIDownloadCache *cache = [[[ASIDownloadCache alloc] init] autorelease];
41-
[cache setStoragePath:NSTemporaryDirectory()];
42-
[cache setShouldRespectCacheControlHeaders:NO];
43-
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:interestingURL] autorelease];
44-
[request setDownloadCache:cache];
45-
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
46-
[request setSecondsToCache:60*60*24];
47-
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy];
48-
[request setCompletionBlock:^{
49-
NSData *interestingJson = [request responseData];
50-
NSDictionary *json= [NSJSONSerialization JSONObjectWithData:interestingJson options:0 error:nil];
30+
31+
32+
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:interestingURL];
33+
34+
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
35+
NSLog(@"connection error: %@", connectionError);
36+
NSLog(@"json: %@", [NSString stringWithUTF8String:[data bytes]]);
37+
NSDictionary *json= [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
5138
NSDictionary *jsonPhotos = [json objectForKey:@"photos"];
5239
NSArray *jsonPhoto = [jsonPhotos objectForKey:@"photo"];
5340
[jsonPhoto enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
54-
AFFlickrPhoto *flickrPhoto = [[[AFFlickrPhoto alloc] initWithDictionary:obj] autorelease];
41+
AFFlickrPhoto *flickrPhoto = [[AFFlickrPhoto alloc] initWithDictionary:obj];
5542
[flickrPhoto downloadPhotoWithCompletionBlock:^{
56-
[self.photos addObject:flickrPhoto];
43+
[self.photos addObject:flickrPhoto];
5744
}];
5845
}];
46+
5947
}];
60-
[request startAsynchronous];
6148
}
6249

6350
- (AFFlickrPhoto *)randomPhoto

FlickrSavr/AFFlickrPhoto.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#import <Foundation/Foundation.h>
2-
#import "ASIHTTPRequest.h"
32

43
@interface AFFlickrPhoto : NSObject
54
- (id)initWithDictionary:(NSDictionary *)dict;
65
- (NSURL *)url;
76
- (NSString *)title;
8-
- (void)downloadPhotoWithCompletionBlock:(ASIBasicBlock)completionBlock;
7+
- (void)downloadPhotoWithCompletionBlock:(void(^)())block;
98
- (NSString *)photoPath;
109
- (NSString *)ownerName;
1110
- (NSURL *)buddyIconURL;

FlickrSavr/AFFlickrPhoto.m

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#import "AFFlickrPhoto.h"
2-
#import "ASIHTTPRequest.h"
32

43
@interface AFFlickrPhoto ()
54
@property (strong) NSMutableDictionary *photoAttributes;
@@ -8,13 +7,6 @@ @interface AFFlickrPhoto ()
87
@implementation AFFlickrPhoto
98
AF_SYNTHESIZE(photoAttributes);
109

11-
- (void)dealloc
12-
{
13-
AF_RELEASE(photoAttributes);
14-
15-
[super dealloc];
16-
}
17-
1810
- (id)initWithDictionary:(NSDictionary *)dict
1911
{
2012
if((self = [super init])) {
@@ -26,7 +18,7 @@ - (id)initWithDictionary:(NSDictionary *)dict
2618

2719
- (NSURL *)url
2820
{
29-
NSString *urlString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/%@_%@_b.jpg",
21+
NSString *urlString = [NSString stringWithFormat:@"https://farm%@.static.flickr.com/%@/%@_%@_b.jpg",
3022
[self.photoAttributes objectForKey:@"farm"],
3123
[self.photoAttributes objectForKey:@"server"],
3224
[self.photoAttributes objectForKey:@"id"],
@@ -41,36 +33,46 @@ - (NSString *)title
4133

4234
- (NSString *)photoPath
4335
{
44-
return [NSString stringWithFormat:@"/%@_%@_b.jpg",
36+
return [NSString stringWithFormat:@"%@/%@_%@_b.jpg",
4537
NSTemporaryDirectory(),
4638
[self.photoAttributes objectForKey:@"id"],
4739
[self.photoAttributes objectForKey:@"secret"]];
4840
}
4941

50-
- (void)downloadPhotoWithCompletionBlock:(ASIBasicBlock)completionBlock
42+
- (void)downloadPhotoWithCompletionBlock:(void(^)())completionBlock
5143
{
5244
NSString *fileName = [self photoPath];
5345
NSFileManager *fileManager = [NSFileManager defaultManager];
5446
if([fileManager fileExistsAtPath:fileName]) {
5547
// file already exists, so just run completion block
5648
completionBlock();
5749
} else {
58-
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[self url]];
59-
[request setDownloadDestinationPath:fileName];
60-
[request setCompletionBlock:^{
61-
if(![request error]) {
62-
completionBlock();
63-
}
64-
}];
65-
[request startAsynchronous];
50+
NSError *error = nil;
51+
NSURLResponse *response = nil;
52+
NSData *responseData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[self url]] returningResponse:&response error:&error];
53+
if(error) {
54+
NSLog(@"Error fetching photo: %@", error);
55+
} else {
56+
NSLog(@"Saving image to %@", fileName);
57+
[responseData writeToFile:fileName atomically:YES];
58+
completionBlock();
59+
}
6660
};
6761

6862

6963
NSString *iconFileName = [self buddyIconPath];
7064
if(![fileManager fileExistsAtPath:iconFileName]) {
71-
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[self buddyIconURL]];
72-
[request setDownloadDestinationPath:iconFileName];
73-
[request startAsynchronous];
65+
NSError *error = nil;
66+
NSURLResponse *response = nil;
67+
NSLog(@"Fetching buddy icon %@", [self buddyIconURL]);
68+
NSData *responseData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[self buddyIconURL]] returningResponse:&response error:&error];
69+
if(error){
70+
NSLog(@"Error fetching buddy icon: %@", error);
71+
} else {
72+
NSLog(@"Saving buddy icon to %@", [self buddyIconPath]);
73+
[responseData writeToFile:[self buddyIconPath] atomically:YES];
74+
}
75+
7476
}
7577
}
7678

@@ -85,7 +87,7 @@ - (NSURL *)buddyIconURL
8587
return nil;
8688
}
8789

88-
NSString *iconURLString = [NSString stringWithFormat:@"http://farm%@.static.flickr.com/%@/buddyicons/%@.jpg",
90+
NSString *iconURLString = [NSString stringWithFormat:@"https://farm%@.static.flickr.com/%@/buddyicons/%@.jpg",
8991
[self.photoAttributes objectForKey:@"iconfarm"],
9092
[self.photoAttributes objectForKey:@"iconserver"],
9193
[self.photoAttributes objectForKey:@"owner"]
@@ -95,7 +97,7 @@ - (NSURL *)buddyIconURL
9597

9698
- (NSString *)buddyIconPath
9799
{
98-
return [NSString stringWithFormat:@"%@/%@.jpg",
100+
return [NSString stringWithFormat:@"%@/%@.jpg",
99101
NSTemporaryDirectory(),
100102
[self.photoAttributes objectForKey:@"owner"]];
101103
}

FlickrSavr/FlickrSavrView.m

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ @implementation FlickrSavrView
1515
AF_SYNTHESIZE(flickrManager);
1616
AF_SYNTHESIZE(isPreview);
1717

18-
- (void)dealloc
19-
{
20-
AF_RELEASE(flickrManager);
21-
22-
[super dealloc];
23-
}
2418
- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
2519
{
2620
self = [super initWithFrame:frame isPreview:isPreview];

0 commit comments

Comments
 (0)