I want to send a quiet push notification to an application that is in the background, then select the current location of the user and send it to the web service.
I implemented push notification methods, as well as those two:
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSDate *fetchStart = [NSDate date];
[self sendLocationToServerWithCompletionHandler:^(UIBackgroundFetchResult result) {
completionHandler(result);
NSDate *fetchEnd = [NSDate date];
NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
NSLog(@"Background Fetch Duration: %f seconds", timeElapsed);
}];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
}
I also created a method that sends the location to the server:
- (void)sendLocationToServerWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
NSDictionary *params = @{
@"UserId" : self.userId,
@"Latitude" : self.latitude,
@"Longitude" : self.longitude
}
ServerManager *manager = [ServerManager sharedManager];
[manager sendLocationToServerWithCompletion:^(BOOL success) {
if (success)
{
completionHandler(UIBackgroundFetchResultNewData);
}
else
{
completionHandler(UIBackgroundFetchResultFailed);
}
}];
}
I just canβt understand how they all work together, whether Apple will approve it, whether it is possible and where the background image of the location is extracted.
Thanks in advance.
source
share