Skip to content

Commit

Permalink
Fix RN import priority, favoring newest version of RN
Browse files Browse the repository at this point in the history
  • Loading branch information
TikiTDO committed Sep 12, 2017
1 parent 34e035a commit 008bc68
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
8 changes: 5 additions & 3 deletions RCTConvert+RNPStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
// Copyright © 2016 Yonah Forst. All rights reserved.
//

#if __has_include("RCTConvert.h")
#import "RCTConvert.h"
#else
#if __has_include(<React/RCTConvert.h>)
#import <React/RCTConvert.h>
#elif __has_include("React/RCTConvert.h")
#import "React/RCTConvert.h"
#else
#import "RCTConvert.h"
#endif

static NSString* RNPStatusUndetermined = @"undetermined";
Expand Down
8 changes: 5 additions & 3 deletions ReactNativePermissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
// Copyright © 2016 Yonah Forst. All rights reserved.
//

#if __has_include("RCTBridgeModule.h")
#import "RCTBridgeModule.h"
#else
#if __has_include(<React/RCTBridgeModule.h>)
#import <React/RCTBridgeModule.h>
#elif __has_include("React/RCTBridgeModule.h")
#import "React/RCTBridgeModule.h"
#else
#import "RCTBridgeModule.h"
#endif

@interface ReactNativePermissions : NSObject <RCTBridgeModule>
Expand Down
56 changes: 30 additions & 26 deletions ReactNativePermissions.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@

#if __has_include(<React/RCTBridge.h>)
#import <React/RCTBridge.h>
#elif __has_include("RCTBridge.h")
#import "RCTBridge.h"
#else
#elif __has_include("React/RCTBridge.h")
#import "React/RCTBridge.h"
#else
#import "RCTBridge.h"
#endif


#if __has_include("RCTConvert.h")
#import "RCTConvert.h"
#else
#if __has_include(<React/RCTConvert.h>)
#import <React/RCTConvert.h>
#elif __has_include("React/RCTConvert.h")
#import "React/RCTConvert.h"
#else
#import "RCTConvert.h"
#endif

#if __has_include("RCTEventDispatcher.h")
#import "RCTEventDispatcher.h"
#else
#if __has_include(<React/RCTEventDispatcher.h>)
#import <React/RCTEventDispatcher.h>
#elif __has_include("React/RCTEventDispatcher.h")
#import "React/RCTEventDispatcher.h"
#else
#import "RCTEventDispatcher.h"
#endif

#import "RNPLocation.h"
Expand Down Expand Up @@ -59,7 +63,7 @@ - (instancetype)init
{
if (self = [super init]) {
}

return self;
}

Expand All @@ -76,11 +80,11 @@ - (dispatch_queue_t)methodQueue {
resolve(@(UIApplicationOpenSettingsURLString != nil));
}


RCT_EXPORT_METHOD(openSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
if (@(UIApplicationOpenSettingsURLString != nil)) {

NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
id __block token = [center addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil
Expand All @@ -89,7 +93,7 @@ - (dispatch_queue_t)methodQueue {
[center removeObserver:token];
resolve(@YES);
}];

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
Expand All @@ -99,9 +103,9 @@ - (dispatch_queue_t)methodQueue {
RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
NSString *status;

switch (type) {

case RNPTypeLocation: {
NSString *locationPermissionType = [RCTConvert NSString:json];
status = [RNPLocation getStatusForType:locationPermissionType];
Expand Down Expand Up @@ -147,7 +151,7 @@ - (dispatch_queue_t)methodQueue {
RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
NSString *status;

switch (type) {
case RNPTypeLocation:
return [self requestLocation:json resolve:resolve];
Expand All @@ -172,7 +176,7 @@ - (dispatch_queue_t)methodQueue {
default:
break;
}


}

Expand All @@ -181,31 +185,31 @@ - (void) requestLocation:(id)json resolve:(RCTPromiseResolveBlock)resolve
if (self.locationMgr == nil) {
self.locationMgr = [[RNPLocation alloc] init];
}

NSString *type = [RCTConvert NSString:json];

[self.locationMgr request:type completionHandler:resolve];
}

- (void) requestNotification:(id)json resolve:(RCTPromiseResolveBlock)resolve
{
NSArray *typeStrings = [RCTConvert NSArray:json];

UIUserNotificationType types;
if ([typeStrings containsObject:@"alert"])
types = types | UIUserNotificationTypeAlert;

if ([typeStrings containsObject:@"badge"])
types = types | UIUserNotificationTypeBadge;

if ([typeStrings containsObject:@"sound"])
types = types | UIUserNotificationTypeSound;


if (self.notificationMgr == nil) {
self.notificationMgr = [[RNPNotification alloc] init];
}

[self.notificationMgr request:types completionHandler:resolve];

}
Expand All @@ -216,7 +220,7 @@ - (void) requestBluetooth:(RCTPromiseResolveBlock)resolve
if (self.bluetoothMgr == nil) {
self.bluetoothMgr = [[RNPBluetooth alloc] init];
}

[self.bluetoothMgr request:resolve];
}

Expand Down

0 comments on commit 008bc68

Please sign in to comment.