皆さん、今晩は !
簡単な質問があります: iOS 7 で didReceiveRemoteNotification:fetch を使用して正しいプッシュ通知を受信したときに [CLLocationManager startUpdateLocation] を有効にする方法は?
今、私は持っています:
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if ([userInfo objectForKey:@"aps"] && [[userInfo objectForKey:@"aps"] objectForKey:@"content-available"])
{
if ([userInfo objectForKey:@"update-location"])
{
[self performSelectorInBackground:@selector(handleLocationNotificationPush:) withObject:completionHandler];
}
if ([userInfo objectForKey:@"update-sensors"])
{
}
}
}
-(void)handleLocationNotificationPush:(void (^)(UIBackgroundFetchResult))completionHandler
{
[CLController.locMgr startUpdatingLocation];
++nbPushReceive;
[self.pushLockForLocation lock];
if ([self.pushLockForLocation waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:25]] == TRUE && self.lastKnownLocation != nil)
{
[self.pushLockForLocation unlock];
// Send my new location to server using HTTP request
[self sendLocationForPushUpdates:self.lastKnownLocation fetchCompletionHandler:completionHandler];
if (![UIApplication sharedApplication].applicationState == UIApplicationStateActive)
// it stops location updates
[self stopAllLocationUpdates];
return;
}
// In case we didn't receive any new position during 25 secondes
[self.pushLockForLocation unlock];
if (![UIApplication sharedApplication].applicationState == UIApplicationStateActive)
{
[self stopAllLocationUpdates];
}
completionHandler(UIBackgroundFetchResultNoData);
}
- (void)locationUpdate:(CLLocation *)location
{
NSLog(@" *** LocationContrller - LocationUpdate location");
self.lastKnownLocation = location;
if (location.horizontalAccuracy < 500)
{
[self.pushLockForLocation signal];
}
}
もちろん、私の CLController デリゲートは同じクラスです (アプリケーションがフォアグラウンドにあるときに位置の更新が機能します)。私のplist.fileでは、「リモート通知」をチェックしています。
何か不足していますか?
ご協力いただきありがとうございます !:D