我試圖將所有推送的通知存儲在覈心數據中並將其顯示給用戶。事實上,我已經做了執行didReceiveRemoteNotification:
,它的工作像它應該:在本地存儲遠程通知
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"%@", userInfo);
Notification *notify = [NSEntityDescription insertNewObjectForEntityForName:@"Notification" inManagedObjectContext:self.managedObjectContext];
notify.timeStamp = [NSDate date];
notify.alert = [[userInfo valueForKeyPath:@"aps"] valueForKeyPath:@"alert"];
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Couldn't save to persistant store.");
}
}
但是,當我在某些條件語句中把這段代碼裏面didFinishLaunchingWithOptions:
:
if (launchOptions != nil)
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
Notification *notify = [NSEntityDescription insertNewObjectForEntityForName:@"Notification" inManagedObjectContext:self.managedObjectContext];
notify.timeStamp = [NSDate date];
notify.alert = [[dictionary valueForKeyPath:@"aps"] valueForKeyPath:@"alert"];
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Couldn't save to persistant store.");
}
}
}
我什麼也沒有......我嘗試創建UIAlertView
,它顯示從aps適當的aler,但是當我嘗試保存到持久存儲和diplay它在MasterViewController中沒有任何反應。
也許有人知道爲什麼?是因爲我打斷了某種生命週期問題嗎?
編輯
我試圖把UIAlertView
當保存成功裏面didFinishLaunchingWithOptions:
和它顯示,所以我想一切都正確保存,但NSFetchedResultController
不顯示這些通知,爲什麼?