【问题标题】:Get all topics the user is subscribed to in Objective-C获取用户在 Objective-C 中订阅的所有主题
【发布时间】:2017-01-09 08:33:36
【问题描述】:

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

我为 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);
}

可能是什么问题?

【问题讨论】:

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


    【解决方案1】:

    请求没有任何称为授权的Key,我想你的意思是说

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

    而不是

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

    【讨论】:

    • 感谢它的工作,但我在 url 字符串中有更多错误需要没有
    猜你喜欢
    • 2019-11-11
    • 1970-01-01
    • 2023-02-02
    • 2017-04-14
    • 2014-09-07
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多