我已經創建了一個應用程序,它使用信標區域和位置管理器來通知用戶它們是否位於區域內並接收依賴於信標區域標識符的通知。 我已經把ibeacons通知警報沒有顯示
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
:
兩個通知和位置服務展在應用程序中請求用戶授權t o收到通知並始終使用位置服務。當用戶同意並且我進入設置/應用程序名稱時,我可以看到位置管理器和通知是允許的。但當應用程序進入信標區域時仍不會出現通知警報。
這是我在應用程序委託用來有該通知的代碼出現在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該工作就像
-(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」聲明瞭選擇器「startShowingLocationNotifications」
我確定這是我需要做的以便正確顯示通知ios8但是我不知道該怎麼做。我搜索了互聯網無濟於事。有人可以幫助我把這些代碼放到正確的地方來獲得正確的通知。
是的,我已經這樣做了。如何在開始顯示本地通知時擺脫錯誤? – user1114881 2014-09-24 16:16:03
請參閱http://stackoverflow.com/questions/24100313/ask-for-user-permission-to-receive-uilocalnotifications-in-ios-8 – pjh68 2014-09-25 13:17:19
我是否需要爲此添加特殊框架 – user1114881 2014-09-25 15:37:40