【问题标题】:ibeacons notification alerts not showing upibeacons 通知警报未显示
【发布时间】:2014-09-23 04:21:18
【问题描述】:

我创建了一个应用程序,它使用信标区域和位置管理器来通知用户是否在区域内,并根据信标区域标识符接收通知。 我放了

 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;

在应用委托的 didFinishLaunchingWithOptions 中:

通知和位置服务都显示在应用程序中,要求用户授予接收通知和始终使用位置服务的权限。当用户同意两者并且我进入设置/应用程序名称时,我可以看到位置管理器和通知是允许的。但是当应用进入信标区域时仍然没有出现通知警报。

这是我在应用程序委托中使用的代码,用于让通知出现在 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?"]) {

    }

然后我收到一个包含上述正文的警报​​。这是一个通用警报,对我没有好处。我想使用我编写的警报,并且在 IOs7 下使用 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);*/
        }

我想使用这个代码

-(void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
    BOOL canUseLocationNotifications = (status == kCLAuthorizationStatusAuthorizedAlways);
    if (canUseLocationNotifications){
        [self startShowingLocationNotifications];
    }
}

显示我编写的 locationNotifications,但是当我在应用程序委托中编写此代码时,我收到错误 No Visible @interface for 'AppDelegate' declares thje selector"startShowingLocationNotifications'

我确定这是在 ios8 中显示正确通知所需要做的,但我不知道该怎么做。我搜索了互联网无济于事。有人可以帮我将此代码放入正确的位置以获得正确的通知。

【问题讨论】:

    标签: notifications ios8 xcode6 ibeacon


    【解决方案1】:

    检查您是否在应用的 -Info.plist 文件中为“NSLocationAlwaysUsageDescription”提供了值。没有这个权限警报视图将不会显示,权限也不会正确设置。

    【讨论】:

    • 是的,我已经这样做了。如何摆脱开始显示本地通知的错误?
    • 我已将 NSLocationManagerAlways 使用在我的 plist 中,并且已放置 [locationManager requestAlwaysAuthorization];在我看来,我已经放置了
    • 我已经收到了这项工作的通知部分,并将很快发布我所做的作为对我原始帖子的编辑。但是我仍然遇到问题,所以我要发布一个新问题。
    猜你喜欢
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多