Есть ли способ узнать текущее местоположение при получении уведомления? - PullRequest
0 голосов
/ 29 марта 2019

Есть ли в iOS способ получить мое текущее местоположение, когда я получаю push-уведомление?

Например, запуск его при получении push-уведомления oneSignal и прочее ...

Так чтоЯ уже пробовал:

a CLLocationManager в службе уведомлений OneSignal - реактивный родной фон-геолокации getCurrentPosition (собственный метод) внутри службы уведомлений OneSignal.

Класс NotificationService.c:

#import <OneSignal/OneSignal.h>
#import <TSLocationManager/TSLocationManager.h>
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
//@property (nonatomic, strong) TSLocationManager *locationManager;
//@property (nonatomic, strong) TSCurrentPositionRequest *cpr;

@end

@implementation NotificationService


- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
  self.receivedRequest = request;
  self.contentHandler = contentHandler;
  self.bestAttemptContent = [request.content mutableCopy];

  [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];
  self.contentHandler(self.bestAttemptContent);

  // DEBUGGING: Uncomment the 2 lines below and comment out the one above to ensure this extension is excuting
  //            Note, this extension only runs when mutable-content is set
  //            Setting an attachment or action buttons automatically adds this
  //NSLog(@"Running NotificationServiceExtension");
 // self.bestAttemptContent.body = [@"[Modified] " stringByAppendingString:self.bestAttemptContent.body];

  // Magic
  NSLog(@"get current position");
  locationManager = [[CLLocationManager alloc] init];
  locationManager.delegate = self;
  locationManager.distanceFilter = kCLDistanceFilterNone;
  locationManager.desiredAccuracy = kCLLocationAccuracyBest;

  if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
    [locationManager requestWhenInUseAuthorization];

  [locationManager startUpdatingLocation];

  [locationManager stopUpdatingLocation];

//  _locationManager = [TSLocationManager sharedInstance];
//  _cpr = [[TSCurrentPositionRequest alloc] initWithSuccess:^(TSLocation *location) {
//  } failure:^(NSError *error) {}];
//  [self.locationManager getCurrentPosition:self.cpr];



}

- (void)serviceExtensionTimeWillExpire {
  // Called just before the extension will be terminated by the system.
  // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.

  [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent];

  self.contentHandler(self.bestAttemptContent);
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(NSArray *)locations {
  NSLog([locations lastObject]);
  NSLog(@"Rapaz, tem uma localizacao aqui");
}




@end

Класс NotificationService.h:

 #import <UserNotifications/UserNotifications.h>
    #import <TSLocationManager/TSLocationManager.h>
    #import <UIKit/UIKit.h>
    #import <CoreLocation/CoreLocation.h>

    #if __has_include("RCTEventEmitter.h")
    #import "RCTEventEmitter.h"
    #else
    #import <React/RCTEventEmitter.h>
    #endif

    #if __has_include("RCTInvalidating.h")
    #import "RCTInvalidating.h"
    #else
    #import <React/RCTInvalidating.h>
    #endif

    @interface NotificationService : UNNotificationServiceExtension <CLLocationManagerDelegate> {
      CLLocationManager *locationManager;
    }

    @end

Не очень хорошо с Objective-C, но я знаю C. Заранее спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...