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

[iOS] Upgrading a plugin with an older method signature for Cordova/PhoneGap 2.7.0 #13

Closed
shazron opened this issue May 6, 2013 · 3 comments

Comments

Projects
None yet
3 participants
@shazron
Copy link
Owner

commented May 6, 2013

When you use a method signature in JavaScript like this:

cordova.exec('MyService.myMethod', myArg1, myArg2, myArg3);

The console log will ask you to upgrade it like this:

The old format of this exec call has been removed (deprecated since 2.1). Change to: cordova.exec(null, null, "MyService", "myMethod", [ myArg1, myArg2, myArg3 ]);

But, if your corresponding Objective-C method uses the old signature like so:

- (void) myMethod:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

Update it to this new signature:

- (void) myMethod:(CDVInvokedUrlCommand*)command;

Also update any references to "arguments" in the method body with "command.arguments".

So if your method looked like this:

- (void) myMethod:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
    NSString* myArgs1 = [arguments objectAtIndex:0];
    NSString* myArgs2 = [arguments objectAtIndex:1];
    NSString* myArgs3 = [arguments objectAtIndex:2];
}

Change it to this:

- (void) myMethod:(CDVInvokedUrlCommand*)command
{
    NSString* myArgs1 = [command.arguments objectAtIndex:0];
    NSString* myArgs2 = [command.arguments objectAtIndex:1];
    NSString* myArgs3 = [command.arguments objectAtIndex:2];
}

This is the easiest upgrade path. If you want to further use the more powerful callback mechanisms provided, see the Plugin Development Guide to upgrade your plugin.

@padzilla

This comment has been minimized.

Copy link

commented May 6, 2013

Great info! I was kind of dreading doing this but it seems pretty straightforward. One quick question though.
If I wanted to get a specfic key, would it just be like this for example :

NSInteger myinteger = [[command.arguments objectAtIndex:0] objectForKey:@"mykey"] intValue];

Thanks again.

@shazron

This comment has been minimized.

Copy link
Owner Author

commented May 6, 2013

If the 1st item in the array is a dictionary (JSON object), yup

@dfsilva

This comment has been minimized.

Copy link

commented Nov 20, 2013

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.