获取用户在Objective-C中订阅的所有主题

时间:2017-01-09 08:33:37

标签: ios objective-c firebase firebase-cloud-messaging

我需要获取用户在我的应用中订阅的主题。

我为Android找到了此question。并尝试将其复制到Objective-C,但我得到一个例外:

-(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

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

请求中没有任何名为Authorization的Key,我想你的意思是

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

而不是

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