使用位置IOS解析推送通知

我熟悉Parse Push通知,但在规划应用程序时,我有一个想法,一旦用户在某个位置(公园,博物馆等)发送推送通知

这可能吗??

这可以很容易地解决。 在您的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]; } }

// 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]; } }

// 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]; } }

 // 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]; } } 

// 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]; } }

请记住在info.plist中添加

“应用程序注册位置更新”