私は2人がブルートゥースでゲームをプレイできるアプリを持っています。あるプレイヤーがプレイの招待状を送信すると、彼らは自分の電話をビーコンに変えています。このビーコンがオンになると、他の人がアプリを持っていれば(レンジ内にあれば)、それらは範囲に入り、通知がポップアップします。これは、アプリが開いているときに効果的です。しかし、アプリがバックグラウンドにあるときは、通知を受け取るが、アプリを復帰させるまでユーザーには表示されません。アプリがバックグラウンドモードになっているときに、通知が表示されるかサウンドが再生されるようにするにはどうすればよいですか。バックグラウンドiOSでビーコン通知を受け取るXcode
私はregion.stateを受信し、通知を表示するために使用するコードです。
-(void)locationManager:(CLLocationManager*)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion*)region{
NSLog(@"manager didDetermineState state forRegion");
UILocalNotification *notification = [[UILocalNotification alloc]init];
if(state == CLRegionStateInside){
NSLog(@"region.identifier;%@",region.identifier);
if ([region.identifier isEqualToString:@"com.checkers.bluetooth"]) {
NSLog(@"region.identifier;%@",region.identifier);
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if([UIScreen mainScreen].bounds.size.height == 480.0){
inviteCheckers.frame = CGRectMake(147,95 *.84,20,20);
}
else {
inviteCheckers.frame = CGRectMake(147,95,20,20);}
}
else if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
inviteCheckers.frame = CGRectMake(64+294,145,40,40);
}
} completion:^ (BOOL completed) {
場合([YOURNAME isEqualToString:@ "なし"]){ notification.alertBody = @ "。あなたはチェッカーを再生するために招待誰かを逃した私はGAMEだと送り出すnOpen招待\"。 [[UIApplication sharedApplication] presentLocalNotificationNow:通知]; } else { NSString * nameString1 = yourName; NSString * nameString2 = [nameString1 stringByAppendingString:@ "チェッカーを再生します。 notification.alertBody = nameString2; AlertView = [[UIAlertView alloc] initWithTitle:@ "ゲームをプレイしますか?" メッセージ:
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:@"CANCEL", nil];
[self.AlertView setBackgroundColor:[UIColor clearColor]];
[AlertView show];} } ];
identifierString = region.identifier;
messageString2 = @"checkers";
recieve.hidden = NO;
}
// notification.alertBodyこれは私が
- (void)applicationDidEnterBackground:(UIApplication *)application
{
if ([backgroundstring isEqualToString:@"fire"]) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = @"Someone wants to play a game.";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
}
を追加した新しいコードで動作するために使用されるようですが、今それはしていません。 私はplistのバックグラウンドモードで位置情報を更新しています。 私は許可を得ます アプリがバックグラウンドにあるときに招待状がありますが、名前は記録されていません。通知が表示されますが、フォアグラウンドにはその人の名前が警告されます。
@ "no fire"から変更された背景文字列を追加しました。 @ "火"に。アラート通知が入ってきて、それが機能するとき。バックグラウンドストリングが@ "fire"のときにローカル通知を送信しようとしました。 (上記のコードを参照)、何も起こりません。私は何かが不足していると確信しているが、何を知らない。 – user1114881
ヒントのおかげでそれを考え出した。私が行ったことを反映するためにコードを投稿します。 – user1114881