0

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.

user1114881
  • 731
  • 1
  • 12
  • 25

1 Answers1

0

Check that you have supplied a value for "NSLocationAlwaysUsageDescription" in your app's -Info.plist file. Without this the permissions alert view won't be shown and the permissions won't be set properly.

pjh68
  • 443
  • 4
  • 6
  • Yes I have done this. How do I get rid of the error on start showing local notifications? – user1114881 Sep 24 '14 at 16:16
  • See http://stackoverflow.com/questions/24100313/ask-for-user-permission-to-receive-uilocalnotifications-in-ios-8 – pjh68 Sep 25 '14 at 13:17
  • I have place the NSLocationManagerAlways use in my plist and I have placed [locationManager requestAlwaysAuthorization]; in my view and I have placed – user1114881 Oct 06 '14 at 15:34
  • I have gotten the notification part of this working and will post what I did shortly as an edit to my original post. However I am still having problems so I am going to post a new question. – user1114881 Oct 14 '14 at 03:28