[英]Get object from push notification and show in modal view controller
In my app when a task is created it sends a push notification to my device, I need to show the task with all the data in a table view, Im actually sending the data in the notification: 在我的应用中,创建任务后,它会将推送通知发送到我的设备,我需要在表视图中显示包含所有数据的任务,我实际上是在通知中发送数据:
{ "aps": { "alert": "test", "sound": "default" }, "task": { "responsible": "39", "userId": "49", "taskDescription": "test", "topicId": "2", "companyId": "1", "dueDate": "05/10/2014" } } {“ aps”:{“ alert”:“ test”,“ sound”:“ default”},“ task”:{“ responsible”:“ 39”,“ userId”:“ 49”,“ taskDescription”:“ test “,” topicId“:” 2“,” companyId“:” 1“,” dueDate“:” 05/10/2014“}}
but the problem is that I dont know how to take all the task info and get it in an object, can anyone help me? 但问题是我不知道如何获取所有任务信息并将其获取到对象中,有人可以帮助我吗?
thanks in advance 提前致谢
First you need to register for push notifications 首先,您需要注册推送通知
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// if ios is 8 then this will run
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
}
else
{
// if ios is 7.x or less this will run
[application registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}
return YES;
}
Worth checking that the application is successfully registered or not using 值得检查应用程序已成功注册或未使用
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
in case of error it will come here, and you can write the reason why it did not registered itself 如果出现错误,它将出现在这里,您可以写下未注册的原因
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(@"Failed to get token, error: %@", error);
}
Then You can get dictionary from the following delegate 然后,您可以从以下代表那里获取字典
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
and from here you can get the keys with the following code 从这里您可以使用以下代码获取密钥
NSDictionary *aps_dictionary = [userInfo objectForKey:@"aps"];
NSDictionary *task_dictionary = [userInfo objectForKey:@"task"];
NSString *responsible = [task_dictionary objectForKey:@"responsible"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.