Parse Push Notifications with Location IOS

2019-06-11 23:50发布

问题:

Im familiar with Parse Push notifications, but while planning an app i had an idea to send a push notification once a user is in a certain location (a park, a museum, etc)

Is this possible??

回答1:

This can be done easy and with out parse. Add this code in your app delegate

// START WITH [self.locationManager startUpdatingLocation];

pragma mark - CLLocationManagerDelegate

/* * locationManager:didUpdateToLocation:fromLocation: * */ - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive)
{
    // ACTIVE APP, pin in a map

}
else
{
    NSLog(@"App is backgrounded. New location is %@", newLocation);

    // LOCAL PUSH IF NEAR. 


   UILocalNotification *notification = [[UILocalNotification alloc] init];
                notification.alertBody = @"You are near";
                [[UIApplication sharedApplication] presentLocalNotificationNow:notification];


}

}

Remember to add in your info.plist

"App registers for location update"