How do I get a notification when my app is in the background iOS

121 Views Asked by At

I have a game app that uses bluetooth to send moves back and forth between two iOS devices. One person can send out an invitation for other players to play and then they can respond in the affirmative if they want to play.
I am currently using UIAlertController to currently display the invitation and response but it only works when the app is in the foreground. I would like to make it so when the app is in the background it is still listening for an invitation and display the invitation when one arrives, even in the background.

Here is the code I am using to get the invitation when the app is in the foreground

if ([region.identifier isEqualToString:@"com.checkers.bluetooth"]) {
                    
                   [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                        
                       
                        
                    } completion:^ (BOOL completed) {}         ];
                   
                    AlertView = [UIAlertController
                                    alertControllerWithTitle:NSLocalizedString(@"PLAYGAME", nil)
                                 message: NSLocalizedString(@"PLAYCHECKERS", nil)
                                              preferredStyle:UIAlertControllerStyleAlert];

                    UIAlertAction* okButton = [UIAlertAction
                                        actionWithTitle:@"OK"
                                                  style:UIAlertActionStyleDefault
                                                handler:^(UIAlertAction * action) {
Do things
                              }];

                    UIAlertAction* cancelButton = [UIAlertAction
                                            actionWithTitle:@"CANCEL"
                                                      style:UIAlertActionStyleDefault
                                                    handler:^(UIAlertAction * action) {
do other things
                        }];

                    [AlertView addAction:okButton];
                    [AlertView addAction:cancelButton];


                    [self presentViewController:AlertView animated:YES completion:nil];

Can someone please help me with this. I had it working with UILocalNotifications but that has been deprecated. So I am stuck.
I would appreciate a tutorial or an example. I am using objective-c.
Thanks

0

There are 0 best solutions below