无法在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中使用上面的代码..任何人都有想法。