Geolocation with local notification like reminder

后端 未结 2 818
夕颜
夕颜 2020-12-30 18:16

i want implement geolocation notification like the app reminders. this is what i have already done:

in App delegate:

self.locationMa         


        
相关标签:
2条回答
  • 2020-12-30 18:39

    Try to use the

    - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
    

    and

    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
    

    delegate methods.

    0 讨论(0)
  • 2020-12-30 18:49

    I can tell you that your radius is more than likely too small to actually trigger an update. You have the radius set to 1 meter. That is going to take a location update almost too precise to register on anything other than testing coordinates you pass in.

    Assuming you get a region event, I would put your local notification in the -didEnterRegion or -didExitRegion methods. You can create your notification like @Missaq said.

    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.fireDate = [NSDate date]; 
    NSTimeZone* timezone = [NSTimeZone defaultTimeZone]; 
    notification.timeZone = timezone; 
    notification.alertBody = @"Notification message"; 
    notification.alertAction = @"Show"; 
    notification.soundName = UILocalNotificationDefaultSoundName; 
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
    [notification release]; // release if not using ARC
    

    Keep in mind that you will not get your notification if your application is active. You will have to be in background mode if you want to see your notification fire. If you application is active, you are expected to present an UIAlertView rather than UILocalNotification. Hope this helps.

    0 讨论(0)
提交回复
热议问题