[ios][storage] now detects if pod installed (makes the pod an optional dependency)

This commit is contained in:
Salakar 2017-05-25 15:14:01 +01:00
parent 410f260fc0
commit 531acece76
2 changed files with 34 additions and 28 deletions

View File

@ -1,7 +1,6 @@
#ifndef RNFirebaseStorage_h #ifndef RNFirebaseStorage_h
#define RNFirebaseStorage_h #define RNFirebaseStorage_h
#import "Firebase.h"
#if __has_include(<React/RCTEventEmitter.h>) #if __has_include(<React/RCTEventEmitter.h>)
#import <React/RCTEventEmitter.h> #import <React/RCTEventEmitter.h>
#else // Compatibility for RN version < 0.40 #else // Compatibility for RN version < 0.40
@ -17,8 +16,6 @@
} }
@property (nonatomic) NSString *_storageUrl;
@end @end
#endif #endif

View File

@ -1,7 +1,9 @@
#import "RNFirebaseStorage.h" #import "RNFirebaseStorage.h"
#import "RNFirebaseEvents.h"
#if __has_include(<FirebaseStorage/FIRStorage.h>)
#import "RNFirebaseEvents.h"
#import <Photos/Photos.h> #import <Photos/Photos.h>
#import "Firebase.h"
@implementation RNFirebaseStorage @implementation RNFirebaseStorage
@ -23,7 +25,7 @@ RCT_EXPORT_MODULE(RNFirebaseStorage);
NSString *message = [error localizedDescription]; NSString *message = [error localizedDescription];
NSDictionary *userInfo = [error userInfo]; NSDictionary *userInfo = [error userInfo];
NSError *underlyingError = [userInfo objectForKey:NSUnderlyingErrorKey]; NSError *underlyingError = userInfo[NSUnderlyingErrorKey];
NSString *underlyingErrorDescription = [underlyingError localizedDescription]; NSString *underlyingErrorDescription = [underlyingError localizedDescription];
switch (error.code) { switch (error.code) {
@ -80,7 +82,7 @@ RCT_EXPORT_MODULE(RNFirebaseStorage);
break; break;
} }
if (userInfo != nil && [userInfo objectForKey:@"data"]) { if (userInfo != nil && userInfo[@"data"]) {
// errors with 'data' are unserializable - it breaks react so we send nil instead // errors with 'data' are unserializable - it breaks react so we send nil instead
reject(code, message, nil); reject(code, message, nil);
} else { } else {
@ -267,7 +269,7 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
PHImageRequestOptions *options = [PHImageRequestOptions new]; PHImageRequestOptions *options = [PHImageRequestOptions new];
options.networkAccessAllowed = true; options.networkAccessAllowed = true;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) { [[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) {
if ([info objectForKey:PHImageErrorKey] == nil) { if (info[PHImageErrorKey] == nil) {
[self uploadData:imageData metadata:metadata path:path resolver:resolve rejecter:reject]; [self uploadData:imageData metadata:metadata path:path resolver:resolve rejecter:reject];
} else { } else {
reject(@"storage/request-image-data-failed", @"Could not obtain image data for the specified file.", nil); reject(@"storage/request-image-data-failed", @"Could not obtain image data for the specified file.", nil);
@ -445,3 +447,10 @@ RCT_EXPORT_METHOD(putFile:(NSString *) path localPath:(NSString *)localPath meta
@end @end
#else
@implementation RNFirebaseStorage
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(nativeSDKMissing) {}
@end
#endif