對於任何條件,檢查用戶是否已經選定,或應用程序在後臺或處於活動狀態。 你只需要檢查
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
if(application.applicationState == UIApplicationStateActive) {
//app is currently active, can update badges count here
}else if(application.applicationState == UIApplicationStateBackground){
//app is in background, if content-available key of your notification is set to 1, poll to your backend to retrieve data and update your interface here
}else if(application.applicationState == UIApplicationStateInactive){
//app is transitioning from background to foreground (user taps notification), do what you need when user taps here
}
你不能這樣做。 – Avi
如果通知仍在通知中心,那麼您將在didFinishLaunching方法中得到它 –
您應該創建一種方法來查詢服務器以查看它是否有未決的通知 – jcesarmobile