0

我无法从 Firebase RemoteConfig 获取信息。在应用安装时,我在 MainController 视图控制器之前有一个语言选择屏幕。在 MainController 视图控制器上,我正在执行 RemoteConfig 获取。它第一次工作,当语言选择屏幕显示在 MainController 视图控制器之前。但是,从下一次开始,它会在这条特定的行上崩溃:

[self.remoteConfig fetchWithExpirationDuration:expirationDuration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {

除了以下情况:

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString firstObject]: unrecognized selector sent to instance 0xa0000000000616a2'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010d20134b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010cc6221e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010d270f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x000000010d186c15 ___forwarding___ + 1013
    4   CoreFoundation                      0x000000010d186798 _CF_forwarding_prep_0 + 120
    5   English                             0x0000000107f44e1b -[GIPLocale googleLanguageWithAppleLanguages:] + 33
    6   English                             0x0000000107f45396 -[GIPLocale recalculateLocale] + 54
    7   English                             0x0000000107f44c26 -[GIPLocale initWithLanguageMappings:] + 99
    8   English                             0x0000000107f44b77 __25+[GIPLocale googleLocale]_block_invoke + 41
    9   libdispatch.dylib                   0x000000010da900cd _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x000000010da751fc dispatch_once_f + 501
    11  English                             0x0000000107f44b4c +[GIPLocale googleLocale] + 42
    12  English                             0x0000000107f42d06 +[RCNDevice deviceLocale] + 31
    13  English                             0x0000000107f43344 +[RCNDevice hasDeviceContextChanged:projectIdentifier:] + 325
    14  English                             0x0000000107f3e133 -[RCNConfigFetch fetchAllConfigsWithExpirationDuration:completionHandler:] + 150
    15  English                             0x0000000107f3577f -[FIRRemoteConfig fetchWithExpirationDuration:completionHandler:] + 77

更新:我是否显示语言选择屏幕都没有关系。它始终适用于全新安装,并在下次启动时停止工作。

这是我正在使用的完整代码。

-(void)viewDidAppear:(BOOL)animated{
    //Display select language settings
    if (![[NSUserDefaults standardUserDefaults] boolForKey:DISPLAY_LANGUAGE_SETTING])
    {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults  setBool:TRUE forKey:DISPLAY_LANGUAGE_SETTING];
        [defaults synchronize];
        //Display Language Screen
        AGSelectLanguageViewController *languageViewController =  [self.storyboard instantiateViewControllerWithIdentifier:@"AGSelectLanguageViewController"];
        self.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:languageViewController animated:NO completion:nil];
    }

  [self configFireBase];

}
  -(void)configFireBase{
        // Firebase Configuration
        self.remoteConfig = [FIRRemoteConfig remoteConfig];
       //Enabling development mode
        FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
        self.remoteConfig.configSettings = remoteConfigSettings;

        //Set default Remote Config values
        [self.remoteConfig setDefaultsFromPlistFileName:@"RemoteConfigDefaults"];

        [self fetchConfig];
    }

- (void)fetchConfig {
    _discount_percentage = self.remoteConfig[DISCOUNT_PERCENTAGE].numberValue.floatValue;

    long expirationDuration = 3600;

    if (self.remoteConfig.configSettings.isDeveloperModeEnabled) {
        expirationDuration = 0;
    }


    [self.remoteConfig fetchWithExpirationDuration:expirationDuration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) {
        if (status == FIRRemoteConfigFetchStatusSuccess) {
            NSLog(@"Config fetched!");
            [self.remoteConfig activateFetched];
        } else {
            NSLog(@"Config not fetched");
            NSLog(@"Error %@", error.localizedDescription);
        }
    }];
}

我哪里错了?请帮忙。

4

1 回答 1

3

GIPLocale 类在 Google 和 Apple 名称之间为语言环境做一些映射,作为其中的一部分,它从 NSUserDefaults 中提取应用程序的语言环境:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];

我猜测默认条目的某处被设置为字符串或类似内容,而不是数组 - 检查您是否在应用程序的任何位置引用该字符串。

于 2016-10-18T16:37:38.140 回答