点击推送通知当应用程序未激活时,强制关闭Xamarin.iOS

时间:2016-06-06 00:28:23

标签: c# ios xamarin push-notification xamarin.ios

推送通知有问题。当我的应用程序在后台运行时,我收到通知,然后点击它的工作通知,然后转到我想要的视图控制器。但是当应用程序关闭并点击通知时,应用程序将被强制关闭。这是我在FinishedLaunching中解析推送通知的方法

private GCMResponse ParseResponse(NSDictionary userInfo)
        {
            NSObject title,
                     message,
                     page;
            userInfo.TryGetValue(new NSString("Title"), out title);
            userInfo.TryGetValue(new NSString("Message"), out message);
            userInfo.TryGetValue(new NSString("Page"), out page);

            return new GCMResponse
            {
                Message = message?.ToString() ?? string.Empty,
                Page = page?.ToString() ?? string.Empty,
                Title = title?.ToString() ?? string.Empty
            };
        }

这就是我解析userInfo

的响应的方法
private void ShowNotifications(GCMResponse response, bool isFromFinishLaunch = false)
        {
                this.Window = new UIWindow(UIScreen.MainScreen.Bounds);
                var activitiesViewController =
                        (ActivitiesViewController)storyboard.InstantiateViewController("ActivitiesViewController");
                    navController.PushViewController(activitiesViewController, false);
                    if (!isFromFinishLaunch)
                    {
                        if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Active)
                        {
                        }
                        else
                        {
                            this.Window.RootViewController = rootController;
                            Window.MakeKeyAndVisible();
                        }
                    }
                    else
                    {
                        this.Window.RootViewController = rootController;
                        Window.MakeKeyAndVisible();
                    }
                    this.RootViewController = rootController;
                }
            }
        }

这就是我将在用户点击推送通知

时显示和处理我应该显示哪个页面的方式
public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {
            var response = this.ParseResponse(userInfo);
            this.ShowNotifications(response);
        }

请注意,我在ReceivedRemoteNotification中也是这样做的,它可以正常工作

{
    "responseHeader": {
        "status": 0,
        "QTime": 1,
        "params": {
            "sort": "title asc"
            "rows": "10"
        }
    },
    "response": {
        "numFound": 3,
        "start": 0,
        "docs": [{
            "title": "Amsterdam",
            "cityurl": "amsterdam"
        }, {
            "title": "London",
            "cityurl": "london"
        }, {
            "title": "New York",
            "cityurl": "new-york"
        }]
    }
}

此外,当应用程序关闭并且我收到推送通知时,如何从Xamarin Studio调试我的应用程序?因为只要应用程序关闭,调试器也会丢失。

0 个答案:

没有答案