Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from inlight-media/1.7
Browse files Browse the repository at this point in the history
Release 1.7
  • Loading branch information
benjaminpearson committed Oct 22, 2014
2 parents 0f9f25a + 01c03cb commit 912cfdc
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Lighthouse/LighthouseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef void (^SubscribeBlock)(id self, NSDictionary *data);
- (void)activate;
- (void)suspend;
- (void)terminate;
- (void)unload;

#pragma mark - Properties
- (void)setProperties:(NSDictionary *)properties;
Expand All @@ -57,6 +58,10 @@ typedef void (^SubscribeBlock)(id self, NSDictionary *data);
+ (void)enableLogging;
+ (BOOL)isLoggingEnabled;

#pragma mark - Bluetooth
- (void)promptBluetooth;
- (BOOL)isBluetoothOn;

#pragma mark - Settings
- (NSDictionary *)settings;

Expand Down
Binary file modified Lighthouse/libLighthouse.a
Binary file not shown.
2 changes: 2 additions & 0 deletions LighthouseExample/LighthouseExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
VALID_ARCHS = "armv7 armv6 arm64 i386";
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -295,6 +296,7 @@
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
VALID_ARCHS = "armv7 armv6 arm64 i386";
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down
44 changes: 39 additions & 5 deletions LighthouseExample/LighthouseExample/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[NSTimer scheduledTimerWithTimeInterval:5 target:[LighthouseManager sharedInstance] selector:@selector(requestPermission) userInfo:nil repeats:NO];


// Request bluetooth permission (you can do this whenever you like - it will ask user to turn on bluetooth if they haven't already - possibly you want to wait until they reach a certain section of your app)
// To fire immediately
// [[LighthouseManager sharedInstance] promptBluetooth];
// In this example we have delayed the permission request by 15 seconds
// You can also check if they have bluetooth enabled already by checking the return BOOL value of [[LighthouseManager sharedInstance] isBluetoothOn];
[NSTimer scheduledTimerWithTimeInterval:15 target:[LighthouseManager sharedInstance] selector:@selector(promptBluetooth) userInfo:nil repeats:NO];


// Request push notification permission (you can do this whenever you like - it will ask user for push notification permission - possibly you want to wait until they reach a certain section of your app)
// To fire immediately
// [[LighthouseManager sharedInstance] requestPushNotifications];
// In this example we have delayed the permission request by 15 seconds
[NSTimer scheduledTimerWithTimeInterval:15 target:[LighthouseManager sharedInstance] selector:@selector(requestPushNotifications) userInfo:nil repeats:NO];
// You can check if they have already given push notification permission by checking the length of [[LighthouseManager sharedInstance] pushNotificationToken]; is greater than 0
[NSTimer scheduledTimerWithTimeInterval:30 target:[LighthouseManager sharedInstance] selector:@selector(requestPushNotifications) userInfo:nil repeats:NO];


// Listen to notifications from Lighthouse
[[LighthouseManager sharedInstance] subscribe:@"LighthouseDidEnterBeacon" observer:self selector:@selector(didEnterBeacon:)];
Expand Down Expand Up @@ -92,14 +102,18 @@ - (void)applicationWillTerminate:(UIApplication *)application {

- (void)didEnterBeacon:(NSDictionary *)data {
NSLog(@"didEnterBeacon %@", data);
// Show message with format "Enter: UUID-Major-Minor"
[self triggerLocalNotification:[NSString stringWithFormat:@"Enter: %@", data[@"key"]]];
}

- (void)didExitBeacon:(NSDictionary *)data {
NSLog(@"didExitBeacon %@", data);
// Show message with format "Exit: UUID-Major-Minor"
[self triggerLocalNotification:[NSString stringWithFormat:@"Exit: %@", data[@"key"]]];
}

- (void)didRangeBeacon:(NSDictionary *)data {
NSLog(@"didRangeBeacon %@", data);
//NSLog(@"didRangeBeacon %@", data);
}

- (void)didReceiveNotification:(NSDictionary *)data {
Expand All @@ -116,15 +130,35 @@ - (void)didReceiveCampaign:(NSDictionary *)data {
// You can then trigger a "campaign action" when the user clicks a button for instance to record how many people
// have see and performed an action on the campaign. For the moment we just wait 15 seconds before triggering
[NSTimer scheduledTimerWithTimeInterval:15 target:[LighthouseManager sharedInstance] selector:@selector(campaignActioned:) userInfo:data repeats:NO];

NSDictionary *notification = [[[LighthouseManager sharedInstance] notifications] lastObject];
[[LighthouseManager sharedInstance] campaignActioned:notification];

// Often you will want to retrieve and action the last notification you received
// NSDictionary *notification = [[[LighthouseManager sharedInstance] notifications] lastObject];
// [[LighthouseManager sharedInstance] campaignActioned:notification];
}

- (void)didUpdateSettings:(NSDictionary *)data {
NSLog(@"didUpdateSettings %@", data);
}

- (void)triggerLocalNotification:(NSString *)text {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = text;
notification.fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState applicationState = application.applicationState;
if (applicationState == UIApplicationStateBackground) {
[application presentLocalNotificationNow:notification];
} else {
[[[UIAlertView alloc] initWithTitle:@"Beacon" message:notification.alertBody delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
}

#pragma mark - Push Notifications

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<array>
<string>location</string>
<string>bluetooth-central</string>
<string>remote-notification</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need to scan beacons in background. You can customise this message in the Info plist.</string>
Expand Down
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ The Lighthouse iOS SDK is designed to be simple to develop with, allowing you to

## Supported iOS Versions

As Lighthouse relies on iBeacon support the SDK only performs functionality on iOS 7 (see supported devices http://support.apple.com/kb/HT6048). However the SDK still runs on iOS 6 apps but performs a graceful silent fallback. Any requests to the SDK will be ignored, you can even check whether the app supports beacons using "- (BOOL)doesDeviceSupportBeacons;" method.
As Lighthouse relies on iBeacon support the SDK only performs functionality on iOS 7 (see supported devices http://support.apple.com/kb/HT6048). However the SDK still runs on iOS 5.1 and above apps but performs a graceful silent fallback. Any requests to the SDK will be ignored, you can even check whether the app supports beacons using "- (BOOL)doesDeviceSupportBeacons;" method.

## SDK Specs

Valid Architectures: armv7 armv7s i386 arm64
Minimum iOS Deployment Target: 5.1
Base SDK support: iOS 8

## Install Guide

Installing the client should be a breeze. If it's not, please let us know at [[email protected]](mailto:[email protected])
Installing the client should be straight forward. If it's not, please let us know at [[email protected]](mailto:[email protected])

### Universal Library

Expand All @@ -24,13 +30,7 @@ Within the folder called "Lighthouse" should be the following contents:
- Lighthouse.h

### Add Files to Xcode
Just drag the Lighthouse folder into your Xcode project.

### Add Required Frameworks
Go into your app's target’s Build Phases screen and add the following (if they don't already exist) to the "Link Binary With Libraries" section.

- CoreLocation.framework
- CoreBluetooth.framework
Just drag the Lighthouse folder which includes those 2 files into your Xcode project.

### Build Settings
Under your application targets "Build Settings" configuration find the "Other Linker Flags" property and set it to "-ObjC".
Expand All @@ -41,17 +41,16 @@ You'll need to import the LighthouseManager.h header into the files that contain
#import "LighthouseManager.h"

### Add Background Modes
In your application plist file (often called "ApplicationName-Info.plist") add a row for
"Required background modes" of type Array. It then needs:
In your application plist file (often called "ApplicationName-Info.plist") add a row for "Required background modes" of type Array. It then needs:

- "App registers for location updates"
- "App downloads content in response to push notifications"
- "App communicates using CoreBluetooth"

These are needed to receive the background beacon notifications.

To support updates in iOS 8 you need to add a string to the plist as well. This describes why your app needs location.
To support updates in iOS 8 you need to add the following Cocoa Keys to the plist. Even for non iOS 8 apps its good practice to include these. They describe why your app needs location.

- "NSLocationAlwaysUsageDescription"
- "NSLocationUsageDescription"

### Compile
Try and compile. It should work!
Expand Down Expand Up @@ -325,6 +324,15 @@ You can also check whether permission has been requested previously using:

[[LighthouseManager sharedInstance] hasRequestedPermission];

### Prompting Bluetooth
Some users have bluetooth turned off and you might want to prompt them to turn it on. iBeacons depends on bluetooth being on to function and the Lighthouse SDK cannot complete "launch" process without it. We don't want the SDK to prompt users automatically, instead we give you the control to prompt the users at any time (usually introducing the user as to why they'll need bluetooth). Once you prompt the user and if they subsequently turn on bluetooth then the SDK will automatically continue the launch process, if they don't turn on bluetooth then it will remain idle until a future time when they enable it.

[[LighthouseManager sharedInstance] promptBluetooth];

You can also check whether bluetooth is on using the following method. This can be help you decide whether you need to show them an introuction screen about the importance of bluetooth.

[[LighthouseManager sharedInstance] isBluetoothOn];

### Requesting Push Notification Permission
Likewise with location permission above you can request push notification permission from a user with the following methods. If your app has already requested permission this will operate silently in the background, it is still important to run them though if you want to receive push notifications for campaigns from the Lighthouse API.

Expand Down Expand Up @@ -362,7 +370,7 @@ You can also view an array of all notifications received (you could for instance

[[LighthouseManager sharedInstance] notifications]

It can also be helpful to have access to the devices push notification token. You can use this in the Admin Integration page to test your push notifications certificates. Just copy/paste the value into the Test Push Notification section and hit send.
It can also be helpful to have access to the devices push notification token. You can use this in the Admin Integration page to test your push notifications certificates. Just copy/paste the value into the Test Push Notification section and hit send. NOTE: this method will return an empty string value if they haven't accepted push notification permission. You can check the length of the string to see whether they accepted or not.

[[LighthouseManager sharedInstance] pushNotificationToken]

Expand Down Expand Up @@ -427,6 +435,20 @@ If a campaign is triggered then a push notification will be sent to the device,

## Changelog

##### 1.7

+ Added "(BOOL)isLocationPermissionAuthorized" method to check if location permission has been authorised
+ Added "(BOOL)isBluetoothOn" method to check if bluetooth is enabled
+ Added "(void)promptBluetooth" method to ask user to turn on bluetooth if they haven't already (use in combination with above check)
+ Added "(void)unload" method to completely reset Lighthouse back to factory defaults
+ Improved "launch" method flow with improved logging when a user hasn't enabled location / bluetooth yet. Call launch in your applicationDidLaunch then just ask for permissions when needed.
+ Further updates for iOS 8 support
+ Stability updates
+ Now supports Minimum Deployment Target of 5.1
+ The distance value for ranged beacons will update faster when in Immediate distance to the beacon, giving a value of 0 rather than relying on RSSI values.
+ Updated installation instructions
+ Updated example application

##### 1.6

+ Update to support iOS 8 "registerForRemoteNotifications" as they have deprecated "registerForRemoteNotificationTypes"
Expand Down

0 comments on commit 912cfdc

Please sign in to comment.