0
알림이 수신되고 앱이 사용자에 의해 닫히거나/종료 될 때 로컬 sqlite 데이터베이스를 업데이트하려고합니다. 앱이 백그라운드 또는 활성 모드 인 경우 모두 잘 작동합니다.푸시 알림에서 sqlite db 업데이트 앱이 닫히고 백그라운드에서 실행되지 않음 iOS
참조 :
-(void)application:(UIApplication)application didReceiveRemoteNotification:(NSDictionary)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"App Background :%@",userInfo);
if(application.applicationState == UIApplicationStateInactive) {
NSLog(@"Inactive");
//Show the view with the content of the push
[self BackgrounCall:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
} else if (application.applicationState == UIApplicationStateBackground) {
NSLog(@"Background");
//Refresh the local model
[self BackgrounCall:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
} else {
NSLog(@"Active");
//Show an in-app banner
[self BackgrounCall:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
}
질문 : 여기 REFERENCE STACK LINK 1
내가 노력하고 코드가 응용 프로그램이 비활성 상태에서 작동하지 않는 이유는. 이 문제에 대한 해결책이 있습니까?
- (BOOL)application:(UIApplication)application didFinishLaunchingWithOptions:(NSDictionary)launchOptions {
// Override point for customization after application launch.
[[Database shareDatabase] createEditableCopyOfDatabaseIfNeeded];
if(launchOptions != nil)
{
// opened from a push notification when the app is closed
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo != nil)
{
NSLog(@"userInfo->%@", [userInfo objectForKey:@"aps"]);
[self application:application didReceiveRemoteNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
}
}
else
{
}
}
사용자가 앱 클릭 알림을 열면 작동합니다. 사건이 작동하지 않는 경우 : 앱이 죽었다, 알림이 수신 됨, 사용자가 알림이 아닌 앱 아이콘을 사용하여 앱을 연 다음 sqlite 업데이트가 없음 –
didFinishLaunchWithOptions 메소드에서 위 코드를 사용하고 있습니까? –
예 ... 위의 업데이트 된 질문을 확인하십시오. 내가 틀린 일을하면 저를 바로 잡으십시오. –