简体   繁体   English

从推送通知中获取对象并在模式视图控制器中显示

[英]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.

相关问题 如何通过推送通知使用TabBarController导航显示视图控制器 - How to show view controller with TabBarController navigation from push notification 从推送通知中打开视图控制器 - Opening a view controller from a push notification 将视图控制器推入模态视图控制器视图 - Push view controller into modal view controller view 使用Swift从推送通知appdelegate更改视图控制器中UIWebView的URL - change URL of UIWebView in view controller from push notification appdelegate with Swift 使用Storyboard Segues将视图控制器从模态推送到模态父级使用的导航控制器 - Push view controller from modal into navigation controller used by parent of the modal using Storyboard segues 如何从呈现为半模式的视图控制器中将视图控制器推为全屏 - How to push a view controller as a full screen from the view controller presented as a half-modal 从Modal View Controller推入/弹出到另一个View Controller(包括图片) - Push/pop to another view controller from a Modal View Controller (includes picture) 如何从多个视图控制器推送到一个视图控制器对象 - How to push to one view controller object from multiple view controllers 取消模态,然后立即推送视图控制器 - Dismiss modal, then immediately push view controller 如何从Tabbar控制器获取UINavigation控制器并推送特定视图 - How to get UINavigation controller from Tabbar controller and push a specific view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM