EluxsanaSubenderan-7718 avatar image
0 Votes"
EluxsanaSubenderan-7718 asked EluxsanaSubenderan-7718 edited

Speaker Identification API. When i try to return a profile Id i get a Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)"

The following error message is what i get when i try to return a profile Id for enrolment. I have already tried to see if it is an authentication error by using the API console, everything seems to be returning fine over there. Currently I am using the objective c code from the link below as a bridge header for my swift app:

Currently this is the error message i receive when i try to return the Profile Id for Enrolment:

" 2021-03-23 14:56:16.205386-0400 Reka[50677:760200] Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=, NSUnderlyingError=0x600002755290 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey=<NSHTTPURLResponse: 0x600002a746a0> { URL: } { Status Code: 401, Headers { "Content-Length" = ( 225 ); "Content-Type" = ( "application/json" ); Date = ( "Tue, 23 Mar 2021 18:56:15 GMT" ); "Strict-Transport-Security" = ( "max-age=31536000; includeSubDomains; preload" ); "Www-Authenticate" = ( "AzureApiManagementKey realm=\"",name="Ocp-Apim-Subscription-Key",type="header\"" ); "apim-request-id" = ( "5ab215e6-1efe-4f92-9468-3dc14a79567e" ); "x-content-type-options" = ( nosniff ); } }}}, NSErrorFailingURLKey=}"

Implementation of my code

@implementation PersonIdObject

  • (int) personIdMethod {
    NSLog(@"SomeMethod Ran");

            @autoreleasepool {
             NSString* path = @"";
             NSArray* array = @[
                                  // Request parameters
             NSString* string = [array componentsJoinedByString:@"&"];
             path = [path stringByAppendingFormat:@"?%@", string];
             NSLog(@"%@", path);
             NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
             [_request setHTTPMethod:@"POST"];
             // Request headers
             [_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
             [_request setValue:@"{subscription key}" forHTTPHeaderField:@"sub_key"];
             // Request body
             [_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
             NSURLResponse *response = nil;
             NSError *error = nil;
             NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
             if (nil != error)
                 NSLog(@"Error: %@", error);
                 NSError* error = nil;
                 NSMutableDictionary* json = nil;
                 NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
                 NSLog(@"%@", dataString);
                 if (nil != _connectionData)
                     json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
                 if (error || !json)
                     NSLog(@"Could not parse loaded json with error:%@", error);
                 NSLog(@"%@", json);
                 _connectionData = nil;
             //[pool drain];
             return 0;


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, it seems to be an authentication issue. Can you verify using the API testing console?

0 Votes 0 ·

It works fine when I use the API testing console with my subscription key.

0 Votes 0 ·

Is it possible to get another look at this issue? I have tried using the API console to test and everything seems to be returning fine over there. This issue only comes up when I try to incorporate the objective c code in as a bridge header in my swift app.

0 Votes 0 ·

0 Answers