-1

I am trying to figure out how to check if region based UILocalNotification is fired or not. I searched and found this Remove fired Location-Based notification when user exits region but its not helpful for me.

I have configured an region based UILocalNotification which will fire when user will enter that particular region and UILocalNotification will deliver when app is closed.

Now when user open the app how I can check that region based UILocalNotification fired or not.

Community
  • 1
  • 1
S.J
  • 3,063
  • 3
  • 33
  • 66

2 Answers2

0

Code snippet:

    -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

    {

        NSString *regionIdentifier = [notification.userInfo objectForKey:@"regionIdentifier”];

        [self removeExistingNotificationWithIdentifier: regionIdentifier];

     }



    -(void)removeExistingNotificationWithIdentifier:(NSString*)regionIdentifier
    {
        NSArray *scheduledNotifications = [[UIApplication sharedApplication]scheduledLocalNotifications];
        for (UILocalNotification *notification in scheduledNotifications)
        {
            NSDictionary *userInfoDict = notification.userInfo;
            if ([[userInfoDict objectForKey:@"regionIdentifier"] isEqualToString:regionIdentifier])
            {
                [[UIApplication sharedApplication]cancelLocalNotification:notification];
            }
        }
    }
PGDev
  • 23,751
  • 6
  • 34
  • 88
-1

Use gpx file to check for region based notifications.

Example: Create a file Location.gpx containing the lat,long of the locations you want the notifications to be fired. The below code contains the lat,long of two locations.

<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
    <wpt lat="28.53191" lon="77.38311">
        <name>Google</name>
    </wpt>
    <wpt lat="28.50848" lon="77.40825">
        <name>Apple</name>
    </wpt>
</gpx>

While debugging, select the Location.gpx file as shown in the image below:

enter image description here

PGDev
  • 23,751
  • 6
  • 34
  • 88
  • I didnt ask that, I asked is my notification is fired or not. – S.J Mar 02 '16 at 08:51
  • If your notification is fired, UIApplicationDelegate's [application:didReceiveLocalNotification](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveLocalNotification:) method will be called and you can extract the information from userInfo dictionary of notification. – PGDev Mar 02 '16 at 08:56
  • But my app is closed when the notification is delivered. – S.J Mar 02 '16 at 09:01
  • whenever you tap on the notification, iOS will run the app in background and [application:didReceiveLocalNotification](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveLocalNotification:) will be called where you will get the reference of the tapped notification. – PGDev Mar 02 '16 at 09:03
  • Can you write a bit detail snippet that will fetch the fired region based localnotification objects so those objects can be deleted. And remember app is in terminated state when notification is delivered. And I dont want to tap on notification, I will open the app by tapping on its icon. – S.J Mar 02 '16 at 09:07
  • without tapping on notification? if you just open the app you won't get any callback of the notification. The app will just be opened normally. – PGDev Mar 02 '16 at 09:15
  • To get a callback for the notification you need to tap on it. – PGDev Mar 02 '16 at 09:16
  • you are an amateur you have no knowledge for this. – S.J Mar 02 '16 at 09:19
  • if you have so much knowledge then why don't you try it yourself instead of asking these stupid questions. – PGDev Mar 02 '16 at 09:20