我正在app delegate中使用以下方法处理我的推送通知:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
NSString *pushtext = [userInfo objectForKey:@"alert"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"News", "")
message:pushtext
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert show];
}
如您所见,我正在UIAlertview中显示通知。除此之外,我希望能够将收到的最近5个通知“保存”到UITableview,供用户以后查看。
我如何a)将数据传递给UITableview并b)保存数据供以后查看(可能通过NSUserdefaults?)
答案 0 :(得分:0)
检索AppDelegate中的当前推送通知文本并将其添加到数组中。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[...]
{
NSMutableArray *alertTextArray = [[NSUserDefaults standardUserDefaults] objectForKey:@"alertTextArray"];
NSDictionary *notifKey = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (notifKey)
{
[alertTextArray addObject:[notifKey objectForKey:@"alert"]];
}
[...]
}
...这就是你可以保存它以供以后使用的方法:
[[NSUserDefaults standardUserDefaults] setObject:alertTextArray forKey:@"alertTextArray"];
[defaults synchronize];