我创建了一个应用程序,它使用信标区域和位置管理器来通知用户他们是否在区域内并接收取决于信标区域标识符的通知。 我已经把
了 NSLocationAlwaysUsageDescription
在应用程序的plist中,我已经放了
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge ;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication]registerUserNotificationSettings:mySettings];
}
和
self.locationManager = [[CLLocationManager alloc] init];
[locationManager requestAlwaysAuthorization];
locationManager.delegate = self;
在app delegate的didFinishLaunchingWithOptions:
通知和位置服务都会显示在应用中,要求用户始终授予接收通知和使用位置服务的权限。当用户同意这两个并且我进入设置/应用程序的名称时,我可以看到位置管理器和通知是允许的。但是,当应用程序进入信标区域时,仍然不会显示通知警报。
这是我在app委托中使用的代码,用于在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?"]) {
}
然后我得到一个具有上述身体的警报。这是一个通用警报,对我没有好处。我想使用我编写的警报,并使用locationNotifications Like
在IOs7下工作-(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);*/
}
我想使用此代码
-(void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
BOOL canUseLocationNotifications = (status == kCLAuthorizationStatusAuthorizedAlways);
if (canUseLocationNotifications){
[self startShowingLocationNotifications];
}
}
显示我写的locationNotifications,但是当我在app delegate中编写这段代码时,我得到错误No Visible @interface for' AppDelegate"声明选择器" startShowingLocationNotifications'
我确定这是我需要做的才能在ios8中显示正确的通知,但我不知道该怎么做。我在互联网上搜索无济于事。有人可以帮我把这些代码放到正确的位置以获得正确的通知。
答案 0 :(得分:0)
检查您是否在应用的-Info.plist文件中提供了“NSLocationAlwaysUsageDescription”的值。如果没有此权限,将不会显示权限警报视图,也不会正确设置权限。