Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/v2.9.0-beta.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoboschini committed Sep 3, 2018
2 parents bc7514d + 7e40176 commit 00a2f27
Show file tree
Hide file tree
Showing 28 changed files with 623 additions and 523 deletions.
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'
}
}

Expand All @@ -34,7 +34,7 @@ android {

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
targetSdkVersion 27
}

lintOptions {
Expand All @@ -45,5 +45,5 @@ android {

dependencies {
implementation 'com.facebook.react:react-native:+'
api 'it.near.sdk:nearit:2.9.4'
api 'it.near.sdk:nearit:2.9.5'
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ private Map<String, Object> getEventContentConstants() {
private Map<String, Object> getStatusConstants() {
return Collections.unmodifiableMap(new HashMap<String, Object>() {
{
put("notified", Recipe.RECEIVED);
put("engaged", Recipe.OPENED);
put("received", Recipe.RECEIVED);
put("opened", Recipe.OPENED);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ declare module 'react-native-nearit' {
}

interface NearItStatuses {
notified: string
engaged: string
received: string
opened: string
}

interface NearItEvent {
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* Copyright (c) 2017 Mattia Panzeri <[email protected]>
* Latest changes by Federico Boschini <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

export { NearItManager as default, constants as NearItConstants } from './lib/NearItManager'
export { NearITPermissions } from './lib/permissions'
Binary file modified ios/NearITSDK/NearITResources.bundle/Info.plist
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified ios/NearITSDK/NearITResources.bundle/NearITResources
Binary file not shown.
151 changes: 0 additions & 151 deletions ios/NearITSDK/NearITResources.bundle/_CodeSignature/CodeResources

This file was deleted.

Binary file modified ios/NearITSDK/libNearIT.a
Binary file not shown.
30 changes: 30 additions & 0 deletions ios/Permissions/RCTConvert+RNNPermissionStatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Federico Boschini <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#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* RNNStatusNeverAsked = @"never_asked";
static NSString* RNNStatusDenied = @"denied";
static NSString* RNNStatusGrantedAlways = @"always";
static NSString* RNNStatusGrantedWhenInUse = @"when_in_use";

typedef NS_ENUM(NSInteger, RNNPermissionType) {
RNNPermissionTypeUnknown,
RNNPermissionTypeLocation,
RNNPermissionTypeNotification
};

@interface RCTConvert (RNNPermissionStatus)

@end
18 changes: 18 additions & 0 deletions ios/Permissions/RCTConvert+RNNPermissionStatus.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018 Federico Boschini <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#import "RCTConvert+RNNPermissionStatus.h"

@implementation RCTConvert (RNNPermissionStatus)

RCT_ENUM_CONVERTER(RNNPermissionType, (@{ @"location" : @(RNNPermissionTypeLocation),
@"notification" : @(RNNPermissionTypeNotification)
}),
RNNPermissionTypeUnknown, integerValue)

@end
17 changes: 17 additions & 0 deletions ios/Permissions/RNNLocationPermission.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2018 Federico Boschini <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#import <Foundation/Foundation.h>
#import "RCTConvert+RNNPermissionStatus.h"

@interface RNNLocationPermission : NSObject

+ (NSString *)getStatus;
- (void)requestWithCompletionHandler:(void (^)(NSString *))completionHandler;

@end
87 changes: 87 additions & 0 deletions ios/Permissions/RNNLocationPermission.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2018 Federico Boschini <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#import "RNNLocationPermission.h"
#import "RCTConvert+RNNPermissionStatus.h"
#import <CoreLocation/CoreLocation.h>

@interface RNNLocationPermission() <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager* locationManager;
@property (copy) void (^completionHandler)(NSString *);
@end

@implementation RNNLocationPermission

+ (NSString *)getStatus {
int status = [CLLocationManager authorizationStatus];
switch (status) {
case kCLAuthorizationStatusAuthorizedAlways:
return RNNStatusGrantedAlways;
case kCLAuthorizationStatusAuthorizedWhenInUse:
return RNNStatusGrantedWhenInUse;
case kCLAuthorizationStatusNotDetermined:
return RNNStatusNeverAsked;
default:
return RNNStatusDenied;
}
}

- (void)requestWithCompletionHandler:(void (^)(NSString *))completionHandler {
NSString *status = [self.class getStatus];
if ([status isEqualToString:RNNStatusNeverAsked]) {
self.completionHandler = completionHandler;

if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
}

[self.locationManager requestAlwaysAuthorization];
} else if ([status isEqualToString:RNNStatusDenied]) {
if (@(UIApplicationOpenSettingsURLString != nil)) {

NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
id __block token = [center addObserverForName:UIApplicationDidBecomeActiveNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
[center removeObserver:token];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
completionHandler(RNNLocationPermission.getStatus);
});
}];

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
} else {
NSLog(@"E_OPEN_SETTINGS_ERROR: Can't open app settings");
completionHandler(status);
}
} else {
completionHandler(status);
}
}

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status != kCLAuthorizationStatusNotDetermined) {
if (self.locationManager) {
self.locationManager.delegate = nil;
self.locationManager = nil;
}

if (self.completionHandler) {
//for some reason, checking permission right away returns denied. need to wait a tiny bit
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
self.completionHandler([RNNLocationPermission getStatus]);
self.completionHandler = nil;
});
}
}
}

@end
17 changes: 17 additions & 0 deletions ios/Permissions/RNNNotificationPermission.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2018 Federico Boschini <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#import <Foundation/Foundation.h>
#import "RCTConvert+RNNPermissionStatus.h"

@interface RNNNotificationPermission : NSObject

+ (NSString *)getStatus;
- (void)requestWithCompletionHandler:(void (^)(NSString*))completionHandler;

@end
Loading

0 comments on commit 00a2f27

Please sign in to comment.