如何在Nativescript

时间:2017-01-24 11:40:22

标签: objective-c angular nativescript angular2-nativescript

无法在nativescript中使用sender方法。我只是想用blows 2将blow代码转换为nativescript。

Objective-c代码:

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
{
    NSLog(@"got auth challange");

    if ([challenge previousFailureCount] == 0) {
        _Authenticated = YES;
        [[challenge sender] useCredential:[NSURLCredential credentialWithUser:pusername password:ppassword  persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
    }
    else
    {
        NSLog(@"Cancel auth challange");

        [[challenge sender] cancelAuthenticationChallenge:challenge];

    }
}

[[challenge sender] useCredential:[NSURLCredential credentialWithUser:pusername password:ppassword  persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];

NativeScript Angular 2代码:

  var MyNSURLConnectionDelegate = NSURLConnection.extend({
                connectionDidReceiveAuthenticationChallenge: function (connection, challenge) {

                    if (challenge.previousFailureCount == 0) {
                        _self._Authenticated = true;
                        //var nsURLCredential = NSURLCredential.credentialWithUserPasswordPersistence("phoneuser", "phoneuser", NSURLCredentialPersistencePermanent);

                        challenge.sender.useCredentialForAuthenticationChallenge(NSURLCredential.credentialWithUserPasswordPersistence("phoneuser", "phoneuser", NSURLCredentialPersistencePermanent), challenge);
                        // [[challenge sender] useCredential:[NSURLCredential credentialWithUser:pusername password:ppassword  persistence:NSURLCredentialPersistencePermanent] forAuthenticationChallenge:challenge];
                    }
                    else {
                        console.log("Cancel auth challange");
                        _self.loader.hide();


                        challenge.sender.cancelAuthenticationChallenge(challenge);
                        // [[challenge sender] cancelAuthenticationChallenge:challenge];

                    }



                }

错误消息:JS ERROR TypeError:undefined不是对象(评估'challenge.sender.useCredentialForAuthenticationChallenge'

如何在nativescript中使用上面的代码..任何人都有想法。

0 个答案:

没有答案