Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ResultHandlers #2

Closed
leecrossley opened this issue Oct 2, 2014 · 4 comments
Closed

No ResultHandlers #2

leecrossley opened this issue Oct 2, 2014 · 4 comments

Comments

@leecrossley
Copy link
Owner

DispatchCommandResult -> ResultHandlers.ContainsKey(result.CallbackId) always fails, as ResultHandlers is an empty array :/

leecrossley added a commit that referenced this issue Oct 2, 2014
@leecrossley
Copy link
Owner Author

The webBrowser_Unloaded method which detaches event handlers of plugin commands (to prevent memory leak on page navigation) clears ALL plugin callbacks (aka ResultHandlers).

This results in the callback being lost and a "Failed to locate callback for id" error.

I'm unable to see a workaround for this without modifying the BaseCommand or NativeExecution.

@leecrossley
Copy link
Owner Author

As a temporary workaround, the platforms\wp8\cordovalib\Commands\BaseCommand.cs DetatchHandlers() method could be replaced with:

        public void DetachHandlers()
        {
            this.OnCommandResult = null;
            this.OnCustomScript = null;
            foreach (string callbackId in new List<string>(ResultHandlers.Keys))
            {
                if (!callbackId.ToLower().Contains("datetimepicker"))
                {
                    RemoveResultHandler(callbackId);
                }
            }
        }

@Frix33
Copy link
Contributor

Frix33 commented Nov 21, 2014

For avoiding monkey patching you can save the handler in selectDate method of DateTimePicker.cs class an then readd that on ResultHandler dictionary before DispatchCommandResult, its work great for me:

public event EventHandler<PluginResult> mySavedHandler;
    ....
public void selectDate(string options)
{
   ....
    if (ResultHandlers.ContainsKey(CurrentCommandCallbackId))
    {
        mySavedHandler = ResultHandlers[CurrentCommandCallbackId];
    }
    ....
}

private void dateTimePickerTask_Completed(object sender, DateTimePickerTask.DateTimeResult e)
{
......
 try {
      if (!ResultHandlers.ContainsKey(CurrentCommandCallbackId))
      {
          ResultHandlers.Add(CurrentCommandCallbackId, mySavedHandler);
      }
        .....
      DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result + ""));
    }
}

Frix33 added a commit to Frix33/cordova-plugin-datetime-picker that referenced this issue Nov 21, 2014
Resolve "No ResultHandler" issues (leecrossley#2 ) without cordova  BaseCommand.cs fix:
leecrossley#2
This was referenced Nov 21, 2014
@leecrossley
Copy link
Owner Author

Great - thanks! I've not it tested yet it but it looks good so I'll merge into master. Not sure why I didn't do this...

leecrossley added a commit that referenced this issue Nov 21, 2014
Fixes #2 save callback handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants