How do I send user to external URL via an iBeacon - objective-c

I am new to the world of iBeacons and Objective-C so please bear with me
I have a very simple app built now that updates a Label when the device approaches an iBeacon. What is the Objective-C code sending the device to an external URL?
For example, as you approach the iBeacon, the device is taken to a Youtube video with an explanation of what you ware seeing.
Any tips are greatly appreciated.

Here is code that will do what you want, but it will only work if the app is in the foreground:
CLLocationManager *_locationManager;
- (void)viewDidLoad
{
[super viewDidLoad];
_locationManager = [[CLLocationManager alloc] init];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:#"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] identifier: #"any-radius-networks-ibeacon-default-uuid"];
[_locationManager startMonitoringForRegion:region];
_locationManager.delegate = self;
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.radiusnetworks.com/radbeacon/"]];
}
You'd have to add extra logic to make it open special URLs for special iBeacons.

Related

How to get iBeacon Notification when the app is in Background mode in ios 10 and above?

I have implemented iBeacon Notification in iOS 10 using objective-c. Can some one help me solve this problem to get the iBeacon in background mode in ios 10?
Even if the app is not running, location events (related to the beacons in this case) are handled the same way as any other app launching events. Every time a phone enters or exits a region while the app is terminated, it will be automatically launched.
application:didFinishLaunchingWithOptions: method (of AppDelegate class) is called with UIApplicationLaunchOptionsLocationKey key existing in launchOptions parameter.
When you verify this key exists (so location was the reason that your app was launched) you should create new instance of ESTBeaconManager class, set delegate to AppDelegate object (or any other object that is working as ESTBeaconManagerDelegate and was created before this event occurred) and start monitoring.
Region you are passing to the startMonitoringForRegion: method is not important, as ESTBeaconManager delegate will receive the most recent region information. You can just pick any of the ones your app registered in iOS. After Monitoring is revoked, app will automatically receive most recent entered/exited region event in beaconManager:didEnterRegion: or beaconManager:didExitRegion: method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([launchOptions objectForKey:#"UIApplicationLaunchOptionsLocationKey"])
{
self.beaconManager = [ESTBeaconManager new];
self.beaconManager.delegate = self;
// don't forget the NSLocationAlwaysUsageDescription in your Info.plist
[self.beaconManager requestAlwaysAuthorization];
[self.beaconManager startMonitoringForRegion:[[ESTBeaconRegion alloc]
initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
identifier:#"AppRegion"]];
}
return YES;
}
-(void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = #"Enter region";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
-(void)beaconManager:(ESTBeaconManager *)manager didExitRegion:(ESTBeaconRegion *)region
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = #"Exit region";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

Ipad Air not recognising iBeacon

I've downloaded app for configuring beacons that I bought from Accent systems. It recognises beacon that is transmitting and I can easily configure it. I've used uuidgen tool to make some UUID for beacon and set it up in application. Let's say that this generated UUID is "XXX-XXX" (I know that it's longer and that it's HEX value). So, how it's set in my beacon is following:
UUID: XXX-XXX
Major : 1111
Minor : 0001
That same UUID I used in my code. I've set my View Controller to CLLocationManagerDelegate and in viewDidLoad method I have following code:
NSUUID *myUUID = [[NSUUID alloc] initWithUUIDString:#"XXX-XXX"];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:myUUID
identifier:#"Company"];
CLLocationManager *locManager = [[CLLocationManager alloc] init];
[locManager setDelegate:self];
[locManager startRangingBeaconsInRegion:region];
I've also set following methods in that view controller, but they never get called:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
I'm testing this on Ipad Air and bluetooth is ON.
Why do that never get called? What am I doing wrong?
You need to ask for location permission in iOS 8, and also added a the usage description string in your plist file.
Check out this answer for more detail: https://stackoverflow.com/a/24063578/361247

How to create a QR Code reader for iOS

I am developing an app for our local business. I already have the live camera in a UIImageView, now I need to know how to read QR codes from the UIImageView and display the content (0000-KKP0-2013) in a label.
So basically I need a QR code scanner which is reading a QR code and save the content in a String. I already used ZXing ("Zebra Crossing") but it is not compatible with iOS 6 and it won't work. Is there an easy code for getting the QR Code content in a String?
Thank you!
This is the code I am using in my .m file:
#import "ZBarSDK.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize vImagePreview;
- (void)viewDidUnload
{
[super viewDidUnload];
vImagePreview = nil;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//----- SHOW LIVE CAMERA PREVIEW -----
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPreset352x288;
/*CALayer *viewLayer = self.vImagePreview.layer;
NSLog(#"viewLayer = %#", viewLayer);*/
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
AVCaptureDevice *device = [self frontCamera];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle the error appropriately.
NSLog(#"ERROR: trying to open camera: %#", error);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"QReader"
message:[NSString stringWithFormat:#"ERROR: Versuch die Kamera zu öffnen ist fehlgeschlagen [%#]",error]
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 1;
[alert show];
}
[session addInput:input];
[session startRunning];
}
- (AVCaptureDevice *)frontCamera {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device position] == AVCaptureDevicePositionFront) {
return device;
}
}
return nil;
}
Now I need to know how to read the QR code from the vImagePreview with the ZBarSDK. And I cant use a UIPickerView
Try ZBar: http://zbar.sourceforge.net/iphone/sdkdoc/install.html
We are using it successfully in our application which supports iOS 4 up to iOS 6.1
In my case I use ZBarReaderView - to see a camera preview, which automatically detects and returns scanned code.
You'll need:
#import "ZBarSDK.h"
ZBarReaderView *readerView;
add this : <ZBarReaderViewDelegate>
and then:
[readerView.scanner setSymbology:ZBAR_QRCODE config:ZBAR_CFG_ENABLE to:0];
readerView.readerDelegate = self;
[readerView start];
- (void)readerView:(ZBarReaderView *)view didReadSymbols: (ZBarSymbolSet *)syms fromImage:(UIImage *)img
{
for(ZBarSymbol *sym in syms)
{
NSLog(#"Did read symbols: %#", sym.data);
}
}
Anyways, just follow these instructions:
http://zbar.sourceforge.net/iphone/sdkdoc/tutorial.html
and then try it out - see if it works for You.
EDIT
Here I uploaded example project I took from here: https://github.com/arciem/ZBarSDK
It has enabled front facing camera. Tested - successfully reads qr code using front facing camera:
http://www.speedyshare.com/fkvqt/download/readertest.zip
or
Once application starts - front camera is shown - scanner is 200x200 large and as a subview.
http://www.speedyshare.com/QZZU5/download/ReaderSample-v3.zip
We looked into this not long ago. ZBar looks good, but it's LGPL-licensed, which is not suitable for use on the App Store. In the end I went with ZXingObjC.
if you want to test the qr codes here are some apps for iphone that might come in handy. iphone qr scanner
OP was looking for something that supported iOS6 two years ago, but for anyone else coming along, this one that I went with wraps the built-in iOS7 functionality:
https://github.com/mikebuss/MTBBarcodeScanner
Anyone looking to implement this in Swift. Check this out:
https://github.com/aeieli/swiftQRCode
Need to change a few syntax errors, otherwise fully working on iOS 8.1
Check this out with apple natively implemented Qr code

How I can set the ABPeoplePickerNavigationController as MainView?

Is it possible to show the whole contact list like the apple addressbook app?
Is there an UI from apple that I can use?
Or do I need to copy the complete contacts with ABAddressBook and build my own ListView?
I know there is the ABPeoplePickerNavigationController and the ABPeoplePickerNavigationControllerDelegate
I allready used the Picker with this code:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addContact];
}
-(void)addContact {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:NO];
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return YES;
}
But actually I don’t want to open a Picker. I need to set this to the main view, without a cancle button.
you cant use just parts of it (well.. technically you could, but I dont think apple would like it :D)
you have to reproduuce it I fear

Any tutorials on how to make a leaderboard and achievements in cocos2d

I have tried google it but I can't find one that looks legit. I have game center all set up just need to get the leaderboard up and achievements up. Any suggestions would be nice. Thank you. Also, since I have my score saved to a string do I some how put that in leaderboards?
Add leader board delegates to your layer class.
#interface MyMainMenu : CCLayer<GKLeaderboardViewControllerDelegate>
Display leader board on your need basis.
-(void)displayLeaderboard
{
GKLeaderboardViewController *leaderboardViewController = [[GKLeaderboardViewController alloc] init];
leaderboardViewController.leaderboardDelegate = self;
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController presentModalViewController:leaderboardViewController animated:YES];
}
Add these two leader board delegates function
#pragma mark GameKit delegate
-(void) achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
[app.navController dismissModalViewControllerAnimated:YES];
}
To submit score:
[[GameCenterManager sharedGameCenterObject] reportScore:score forCategory: kLeaderboardID];
Use GameCenterManager.m class from GKTapper sample (see your apple sdk sample).
Here is code to get value from preference:
// To get saved value from pref
int highScore = [[[NSUserDefaults standardUserDefaults] objectForKey:#"HighScore"] intValue ];
There is a whole chapter on game center programming, with sample code, in Itterheim & Loew's book "Learn Cocos2d Game Development with iOS5". Also "Learning Cocos2d" by Strougo & Wenderlich has a chapter with working code.