Skip to content

Commit

Permalink
Since iOS 8 the Location Services Authorization flow changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
napoapo77 committed Nov 24, 2014
1 parent c07ca5b commit f2ed90f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Estimote Editor.xcodeproj/project.pbxproj
Expand Up @@ -42,6 +42,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
365C4F591A23B4FB00AD5468 /* Estimote Editor.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Estimote Editor.entitlements"; sourceTree = "<group>"; };
9E30ED45188EDC30007EE0A7 /* EELinkButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EELinkButton.h; path = EELinkButton/EELinkButton.h; sourceTree = "<group>"; };
9E30ED46188EDC30007EE0A7 /* EELinkButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EELinkButton.m; path = EELinkButton/EELinkButton.m; sourceTree = "<group>"; };
9E439516188FE89200A5908D /* EEBeaconCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EEBeaconCell.h; path = EEBeaconCell/EEBeaconCell.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -225,6 +226,7 @@
E1F1248218338F2700BE137D /* Estimote Editor */ = {
isa = PBXGroup;
children = (
365C4F591A23B4FB00AD5468 /* Estimote Editor.entitlements */,
E10877AE1833DEB800ECD3B3 /* Views */,
E1F124AB18338F5900BE137D /* ViewControllers */,
E1F1248B18338F2700BE137D /* EEAppDelegate.h */,
Expand Down Expand Up @@ -312,7 +314,15 @@
ORGANIZATIONNAME = "Yoann Gini";
TargetAttributes = {
E1F1247818338F2700BE137D = {
DevelopmentTeam = CRXPBZF3N4;
DevelopmentTeam = 8MTW2U4D7Z;
SystemCapabilities = {
com.apple.BackgroundModes = {
enabled = 0;
};
com.apple.WAC = {
enabled = 0;
};
};
};
};
};
Expand Down
4 changes: 3 additions & 1 deletion Estimote Editor/Supporting Files/Estimote Editor-Info.plist
Expand Up @@ -25,9 +25,11 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>83</string>
<string>85</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>So this app can range the beacons</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
Expand Up @@ -17,15 +17,18 @@

#import "EEDataProvider.h"

#import <CoreLocation/CoreLocation.h>

#define REGION_BASE_NAME @"me.gini.estimote.region."

@interface EETableViewController () <ESTBeaconManagerDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
@interface EETableViewController () <ESTBeaconManagerDelegate, CLLocationManagerDelegate, UISearchBarDelegate, UISearchDisplayDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) UISearchBar *searchBar;
@property (nonatomic, strong) UISearchDisplayController *searchController;
@property (nonatomic, strong) NSMutableDictionary *beaconsPerRegion;
@property (nonatomic, strong) NSMutableArray *regionList;
@property (nonatomic, strong) CLLocationManager *locationManager;

@end

Expand All @@ -38,6 +41,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;
self.beaconManager.avoidUnknownStateBeacons = YES;
Expand Down Expand Up @@ -81,12 +87,17 @@ -(void)viewDidLoad
target:self
action:@selector(showCredits)];
[self.navigationItem setLeftBarButtonItem:barButtonItem];

// Since iOS 8 it needs authorization in a different way
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager performSelector:@selector(requestWhenInUseAuthorization) withObject:nil];
}

for (NSString *UUIDString in [[EEDataProvider sharedInstance] regionIdentifierHistory]) {
[self startRangingRegionWithUUID:UUIDString];
}

[[[EEDataProvider sharedInstance] regionIdentifierHistory] addObject:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"];
[[[EEDataProvider sharedInstance] regionIdentifierHistory] addObject:ESTIMOTE_PROXIMITY_UUID.UUIDString];
}

#pragma mark - Internal
Expand All @@ -104,7 +115,13 @@ - (void)startRangingRegionWithUUID:(NSString*)UUIDString
[self.regionList addObject:regionIdentifier];
ESTBeaconRegion* region = [[ESTBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:UUIDString]
identifier:regionIdentifier];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
region.notifyEntryStateOnDisplay = NO;

[self.beaconManager startMonitoringForRegion:region];

[self.beaconManager requestStateForRegion:region];
[self.beaconManager startRangingBeaconsInRegion:region];

}
Expand All @@ -119,8 +136,19 @@ - (void)showCredits
[self.navigationController pushViewController:creditViewController animated:YES];
}

#pragma mark - Core Location Delegate
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
[self dataProviderNewRegionIdentifierAddedToHistory:[NSNotification notificationWithName:kEEDataProviderNewRegionIdentifierAddedToHistory object:self userInfo:@{kEEDataProviderNewRegionIdentifierKey: ESTIMOTE_PROXIMITY_UUID.UUIDString}]];
}

#pragma mark - ESTBeaconManagerDelegate

-(void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region {
NSLog(@"did enter region %@",region);
[self.beaconManager startRangingBeaconsInRegion:region];
}

-(void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
{
NSMutableArray *beaconsList = nil;
Expand Down

0 comments on commit f2ed90f

Please sign in to comment.