Skip to content

Commit

Permalink
Merge remote-tracking branch 'Raaxcat/feature/OSX-Support' into devel…
Browse files Browse the repository at this point in the history
…opment

# Conflicts:
#	Classes/DevedUpKit/FKDUStreamUtil.h
#	Classes/DevedUpKit/FKDUStreamUtil.m
#	Classes/FlickrKit.h
#	Classes/FlickrKit/FlickrKit.m
#	Classes/Network/FKImageUploadNetworkOperation.h
#	Classes/Network/FKImageUploadNetworkOperation.m
#	DemoProject/FlickrKitDemo/FlickrKitDemo.xcodeproj/project.pbxproj
#	DemoProject/FlickrKitDemo/FlickrKitDemo/FKAppDelegate.m
#	FlickrKit.xcodeproj/project.pbxproj
  • Loading branch information
devedup committed Nov 3, 2015
2 parents 7512155 + c1a5dad commit 7ed0e1f
Show file tree
Hide file tree
Showing 23 changed files with 2,895 additions and 49 deletions.
24 changes: 22 additions & 2 deletions Classes/FlickrKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,34 @@
// Copyright (c) 2013 DevedUp Ltd. All rights reserved. http://www.devedup.com
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
//! Project version number for FlickrKit.
FOUNDATION_EXPORT double FlickrKitVersionNumber;

//! Project version string for FlickrKit.
FOUNDATION_EXPORT const unsigned char FlickrKitVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <FlickrKitOSX/PublicHeader.h>

#import "FKDUDiskCache.h"
#import "FKDataTypes.h"
#import "FKFlickrNetworkOperation.h"
#import "FKImageUploadNetworkOperation.h"
#import "FKFlickrAPIMethod.h"
#import "FKAPIMethods.h"

//for module umbrella header
#import "FKDUBlocks.h"
#import "FKDUDefaultDiskCache.h"
#import "FKDUNetworkController.h"
#import "FKDUReachability.h"
#import "FKDUStreamUtil.h"
#import "FKOFHMACSha1Base64.h"
#import "FKUploadRespone.h"
#import "FKURLBuilder.h"
#import "FKUtilities.h"


@class FKFlickrNetworkOperation;

/**
Expand Down Expand Up @@ -133,7 +153,7 @@

@interface FlickrKit (PhotoUpload)

- (FKImageUploadNetworkOperation *) uploadImage:(UIImage *)image args:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion;
- (FKImageUploadNetworkOperation *) uploadImage:(DUImage *)image args:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion;

#if TARGET_OS_IOS
- (FKImageUploadNetworkOperation *) uploadAssetURL:(NSURL *)assetURL args:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion;
Expand Down
8 changes: 8 additions & 0 deletions Classes/FlickrKit/FKDataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ NSString *FKPermissionStringForPermission(FKPermission permission);

NSString *FKIdentifierForSize(FKPhotoSize size);

/*
Define platform specific image wrapper class.
*/
#if TARGET_OS_IPHONE
typedef UIImage DUImage;
#else
typedef NSImage DUImage;
#endif
7 changes: 3 additions & 4 deletions Classes/FlickrKit/FlickrKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -451,19 +451,18 @@ - (NSURL *) photoURLForSize:(FKPhotoSize)size photoID:(NSString *)photoID server


@implementation FlickrKit (PhotoUpload)

- (FKImageUploadNetworkOperation *) uploadImage:(UIImage *)image args:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion {
- (FKImageUploadNetworkOperation *) uploadImage:(DUImage *)image args:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion {
FKImageUploadNetworkOperation *imageUpload = [[FKImageUploadNetworkOperation alloc] initWithImage:image arguments:args completion:completion];
[[FKDUNetworkController sharedController] execute:imageUpload];
return imageUpload;
}

#if TARGET_OS_IOS
- (FKImageUploadNetworkOperation *) uploadAssetURL:(NSURL *)assetURL args:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion {
FKImageUploadNetworkOperation *imageUpload = [[FKImageUploadNetworkOperation alloc] initWithAssetURL:assetURL
FKImageUploadNetworkOperation *imageUpload = [[FKImageUploadNetworkOperation alloc] initWithAssetURL:assetURL
arguments:args
completion:completion];
[[FKDUNetworkController sharedController] execute:imageUpload];
[[FKDUNetworkController sharedController] execute:imageUpload];
return imageUpload;
}
#endif
Expand Down
6 changes: 4 additions & 2 deletions Classes/Network/FKDUReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ + (BOOL) isConnected {
// ... and no [user] intervention is needed
isConnected = YES;
}
} else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
}
#if TARGET_OS_IPHONE
else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
// ... but WWAN connections are OK if the calling application
// is using the CFNetwork (CFSocketStream?) APIs.
isConnected = YES;
}
#endif
CFRelease(reachability);
return isConnected;
}
Expand Down
10 changes: 6 additions & 4 deletions Classes/Network/FKImageUploadNetworkOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
//

#import "FKDUNetworkOperation.h"
#import <UIKit/UIKit.h>
#import "FKDataTypes.h"

@interface FKImageUploadNetworkOperation : FKDUNetworkOperation

@interface FKImageUploadNetworkOperation : FKDUNetworkOperation
@property (nonatomic, assign, readonly) CGFloat uploadProgress;

- (id) initWithImage:(UIImage *)image arguments:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion;
- (id) initWithImage:(DUImage *)image arguments:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion;

#if TARGET_OS_IOS
- (id) initWithAssetURL:(NSURL *)assetURL arguments:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion;
#endif

@end

@interface FKImageUploadNetworkOperation (ImageSerialization)
+ (NSData *) jpegSerialzation:(DUImage *)image;
@end
29 changes: 21 additions & 8 deletions Classes/Network/FKImageUploadNetworkOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#import "FKDUStreamUtil.h"

@interface FKImageUploadNetworkOperation ()
@property (nonatomic, strong) UIImage *image;

@property (nonatomic, strong) DUImage *image;
@property (nonatomic, retain) NSString *tempFile;
@property (nonatomic, copy) FKAPIImageUploadCompletion completion;
@property (nonatomic, retain) NSDictionary *args;
Expand All @@ -27,13 +28,10 @@ @interface FKImageUploadNetworkOperation ()

@implementation FKImageUploadNetworkOperation

- (id) initWithImage:(UIImage *)image arguments:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion; {
- (id) initWithImage:(DUImage *)image arguments:(NSDictionary *)args completion:(FKAPIImageUploadCompletion)completion; {
self = [super init];
if (self) {
self.image = image;
#if TARGET_OS_IOS
self.assetURL = nil;
#endif
self.args = args;
self.completion = completion;
}
Expand Down Expand Up @@ -130,10 +128,9 @@ - (NSMutableURLRequest *) createRequest:(NSError **)error {
[outputStream open];

if( self.image ){
NSData *jpegData = [FKImageUploadNetworkOperation jpegSerialzation:self.image];
// Input stream is the image
NSData *imgData = UIImageJPEGRepresentation(self.image, 1.0);
NSInputStream *inImageStream = [[NSInputStream alloc] initWithData:imgData];

NSInputStream *inImageStream = [[NSInputStream alloc] initWithData:jpegData];
// Write the contents to the streams... don't cross the streams !
[FKDUStreamUtil writeMultipartStartString:multipartOpeningString imageStream:inImageStream toOutputStream:outputStream closingString:multipartClosingString];
}
Expand Down Expand Up @@ -217,6 +214,22 @@ - (void) connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)byt
#endif
}

#pragma mark - ImageSerialization

#if TARGET_OS_IPHONE
+(NSData*)jpegSerialzation:(DUImage *)image{
return UIImageJPEGRepresentation(image, 1.0);
}
#else
+(NSData*)jpegSerialzation:(DUImage *)image{
NSData *imageData = [image TIFFRepresentation];
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
NSNumber *compressionFactor = [NSNumber numberWithFloat:1.0];
NSDictionary *imageProps = [NSDictionary dictionaryWithObject:compressionFactor
forKey:NSImageCompressionFactor];
return [imageRep representationUsingType:NSJPEGFileType properties:imageProps];
}
#endif
@end


Expand Down
15 changes: 15 additions & 0 deletions DemoProject/FlickrKitDemo/FlickrKitDemo-OSX/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// FlickrKitDemo-OSX
//
// Created by raxcat on 2015/10/4.
// Copyright © 2015年 DevedUp Ltd. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>


@end

51 changes: 51 additions & 0 deletions DemoProject/FlickrKitDemo/FlickrKitDemo-OSX/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// AppDelegate.m
// FlickrKitDemo-OSX
//
// Created by raxcat on 2015/10/4.
// Copyright © 2015年 DevedUp Ltd. All rights reserved.
//

#import "AppDelegate.h"
@import FlickrKit;
@interface AppDelegate ()
{
NSWindowController * _mainWindowController;
}
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSString *apiKey = @"348ea26ca45d5f9d3da7fff4822a7fd1";
NSString *secret = @"471cc96b04e60f27";
if (!apiKey) {
NSLog(@"\n----------------------------------\nYou need to enter your own 'apiKey' and 'secret' in FKAppDelegate for the demo to run. \n\nYou can get these from your Flickr account settings.\n----------------------------------\n");
exit(0);
}
[[FlickrKit sharedFlickrKit] initializeWithAPIKey:apiKey sharedSecret:secret];

[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleIncomingURL:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];

_mainWindowController = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"mainWindowController"];
[_mainWindowController showWindow:nil];


}

- (void)handleIncomingURL:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{

NSURL *callbackURL = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
NSLog(@"Callback URL: %@", [callbackURL absoluteString]);

[[NSNotificationCenter defaultCenter] postNotificationName:@"kCallbackURLNotification" object:self userInfo:@{@"callbackURL": callbackURL}];

}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
13 changes: 13 additions & 0 deletions DemoProject/FlickrKitDemo/FlickrKitDemo-OSX/AuthViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// AuthViewController.h
// FlickrKitDemo
//
// Created by raxcat on 2015/10/4.
// Copyright © 2015年 DevedUp Ltd. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface AuthViewController : NSViewController

@end
25 changes: 25 additions & 0 deletions DemoProject/FlickrKitDemo/FlickrKitDemo-OSX/AuthViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AuthViewController.m
// FlickrKitDemo
//
// Created by raxcat on 2015/10/4.
// Copyright © 2015年 DevedUp Ltd. All rights reserved.
//

#import "AuthViewController.h"

@interface AuthViewController ()

@end

@implementation AuthViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
}
- (IBAction)exit:(id)sender {
[self.view.window close];
}

@end
Loading

0 comments on commit 7ed0e1f

Please sign in to comment.