1

I need to get which topics the user subscribe in my app.

I found this question for Android. And try to copy this to Objective-C, but I get an exception:

-(void)getUserTopicSubscribeWithToken
{
    NSString *token = [[FIRInstanceID instanceID] token];

    NSString *urlString = [NSString stringWithFormat:@"https://iid.googleapis.com/iid/info/<%@>?details=true",token];
    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setHTTPMethod:@"GET"];
    //set the content type to JSON
    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    [request setValue:@"Authorization" forKey:@"FIREBASE_KEY"];

    [request setURL:url];

    NSError *error = nil;
    NSHTTPURLResponse *responseCode = nil;

    NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];

    NSString * topics =  [[NSString alloc] initWithData:oResponseData encoding:NSUTF8StringEncoding];

    NSLog(@"%@",topics);
}

linter: Line 587 Thread 1 signal SIGABRT

what can be the problem ?

Community
  • 1
  • 1
Roei Nadam
  • 1,780
  • 1
  • 15
  • 33

1 Answers1

1

The request does not have any Key called Authorization, I think you mean to say

[request setValue:@"FIREBASE_KEY" forHTTPHeaderField:@"Authorization"];

rather than

[request setValue:@"Authorization" forKey:@"FIREBASE_KEY"];
IronMan
  • 1,505
  • 1
  • 12
  • 17