I am using pushwoosh to push notification . I have implemented function receiving push follow pushwoosh documentation, and my application can receive notification normally, however, when application goes to background (close app or suspend), background task did not receive push-notification (push notification trigger is not called). Please read my code and help me to solve this problem.

Here is my code for receive push notification from pushwoosh and init background task:

private async void initBackgroundTask(){ string myTaskName = "Mytask"; await BackgroundExecutionManager.RequestAccessAsync();

    foreach (var cur in BackgroundTaskRegistration.AllTasks)
        if (cur.Value.Name == myTaskName)
        {

            await (new MessageDialog("Task already registered")).ShowAsync();
            cur.Value.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
            return;
        }

    // Windows Phone app must call this to use trigger types (see MSDN)


    // register a new task
    BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder { Name = myTaskName, TaskEntryPoint = typeof(KatzBackgroundStuff.KatzBackgroundTask).ToString() };
    //taskBuilder.SetTrigger(new PushNotificationTrigger());
    taskBuilder.SetTrigger(new PushNotificationTrigger());
    BackgroundTaskRegistration myFirstTask = taskBuilder.Register();
    myFirstTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted); ;
    await (new MessageDialog("Task registered")).ShowAsync();


}

private void initPush()
{
    NotificationService service = PushSDK.NotificationService.GetCurrent(CLIENT_ID);
    service.OnPushAccepted += (sender, pushNotification) => {
        //code to handle push notification
        string pushString = pushNotification.ToString(); //will return json push payload
    };

    //public event EventHandler<PushNotificationReceivedEventArgs> OnPushReceived;




    service.OnPushReceived += (sender, pushAgr) =>
    {
        //received push
        string message = pushAgr.ToastNotification.Content.InnerText;
    };
    service.OnPushTokenReceived += (sender, pushToken) => {
        //code to handle push token
    };

    service.OnPushTokenFailed += (sender, errorMessage) => {
        //code to handle push subscription failure
    };

    service.SubscribeToPushService();

}
asked 19 May '16, 10:39
B%C3%B9i%20Minh%20Th%E1%BA%AFng's gravatar image

Bùi Minh Thắng
12

edited 19 May '16, 10:40

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×326
×26
×11

question asked: 19 May '16, 10:39

question was seen: 1,375 times

last updated: 19 May '16, 10:40