I have created an app that uses beacon regions and location manager to notify users if they are inside a region and receive notifications dependent upon the beacon region identifier. I have put
NSLocationAlwaysUsageDescription
in the app's plist and I have put
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge ;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication]registerUserNotificationSettings:mySettings];
}
and
self.locationManager = [[CLLocationManager alloc] init];
[locationManager requestAlwaysAuthorization];
locationManager.delegate = self;
in the app delegate's didFinishLaunchingWithOptions:
Both notification and location services show up in the app to ask users to give permission to receive notifications and to use location services always. When the user agrees to both and I go into the settings/ the app's name I can see that the location manager and notifications are allow. but still no notification alerts appear when the app enters the beacon region.
This is the code I used in the app delegate to have the notification appear in ios8
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
notification.alertBody = @"Want to play checkers.";
AlertView= [[UIAlertView alloc] initWithTitle:@"Play a Game?"
message:notification.alertBody
delegate:NULL
cancelButtonTitle:@"OK"
otherButtonTitles:@"CANCEL", nil];
[AlertView show];
if ([notification.alertBody isEqualToString:@"Want to play Chess?"]) {
}
then I get an alert which has the body described above. This is a generic alert and does me no good. I want to use the alerts that I have written and that worked under IOs7 using locationNotifications Like
-(void)locationManager:(CLLocationManager*)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion*)region{
UILocalNotification *notification = [[UILocalNotification alloc]init];
if(state == CLRegionStateInside){
if ([region.identifier isEqualToString:@"com.checkers.bluetooth"]) {
NSLog(@"beaconRegion2proximityUUID;%@",beaconRegion2.proximityUUID);
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{inviteCheckers.frame = CGRectMake(147,55,20,20); } completion:^ (BOOL completed) {} ];
notification.alertBody = @"Want to play checkers.";
AlertView= [[UIAlertView alloc] initWithTitle:@"Play a Game?"
message:notification.alertBody
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"CANCEL", nil];
[AlertView show];
identifierString = region.identifier;
/* NSLog(@"identity:%@",identifierString);*/
messageString2 = @"checkers";
}
if ([region.identifier isEqualToString:@"com.chess.bluetooth"]) {
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{inviteChess.frame = CGRectMake(147,108,20,20); } completion:^ (BOOL completed) {} ];
notification.alertBody = @"Want to play Chess?";
AlertView= [[UIAlertView alloc] initWithTitle:@"Play a Game?"
message:notification.alertBody
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"CANCEL", nil];
[AlertView show];
identifierString = region.identifier;
messageString2 = @"chess";
/* NSLog(@"identity:%@",identifierString);*/
}
I would like to use this code
-(void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
BOOL canUseLocationNotifications = (status == kCLAuthorizationStatusAuthorizedAlways);
if (canUseLocationNotifications){
[self startShowingLocationNotifications];
}
}
to have the locationNotifications that I have written show up but when I write this code in the app delegate I get the error No Visible @interface for 'AppDelegate" declares thje selector"startShowingLocationNotifications'
I'm sure this is what I need to do to have the correct notifications show up in ios8 but I don't know how to do it. I have searched the internet to no avail. Can someone please help me to put this code into the correct place to get the right notifications.