Search code examples
iphoneiosobjective-cuiwebviewdelegate

ios - How to declare setToken method?


I'm trying to get access token from Google,Yahoo.But I'm getting an error like WACloudAccessControlClient may not respond to setToken.How to declare setToken method here.

-(BOOL)webView:(UIWebView *)webView
     shouldStartLoadWithRequest:(NSURLRequest *)request
                 navigationType:(UIWebViewNavigationType)navigationType

{

if(_url)
{
    /* make the call re-entrant when we re-load the content ourselves */
    if([_url isEqual:[request URL]])
    {
        return YES;
    }

    [_url release];
}

_url = [[request URL] retain];
NSString* scheme = [_url scheme];

if([scheme isEqualToString:@"acs"])
{
    // parse the JSON URL parameter into a dictionary
    NSDictionary* pairs = [self parsePairs:[_url absoluteString]];
    if(pairs)
    {
        WACloudAccessToken* accessToken;
        accessToken = [[WACloudAccessToken alloc] initWithDictionary:pairs];
        [WACloudAccessControlClient setToken:accessToken];

        [self dismissModalViewControllerAnimated:YES];
    }

    return NO;
}

[NSURLConnection connectionWithRequest:request delegate:self];

return NO;
}

Any ideas? Thanks in advance.


Solution

  • You need to pass the message to an object not a class name so first get a reference to an object.

    I'm not sure what is your usecase, just look at WACloudAccessControlClient api it will have some init or ...with... methods to create or get a reference to an object of the class.

    This:

    [WACloudAccessControlClient setToken:accessToken];
    

    Should be something like (the init... method is made up, please replace with actual one):

    [[WACloudAccessControlClient initSomethingSomehow] setToken:accessToken];
    

    Are you after something like this?:

    [[WACloudAccessControlClient accessControlClientForNamespace:@“namespace-name”
                                                           realm:@“realm-name”]
                                 setToken:accessToken];
    

    Edit:

    Have a look at this example of how to interact with wa toolkit for iOS I've just skimmed through but it seems to have answers you are looking for.