ViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "ViewController.h"
  15. #import <FirebaseAnalytics/FirebaseAnalytics.h>
  16. #import <FirebaseCore/FIROptions.h>
  17. #import <FirebaseCore/FirebaseCore.h>
  18. #import <FirebaseInstallations/FirebaseInstallations.h>
  19. #import <FirebaseRemoteConfig/FirebaseRemoteConfig.h>
  20. #import "../../../Sources/Private/FIRRemoteConfig_Private.h"
  21. #import "FRCLog.h"
  22. static NSString *const FIRPerfNamespace = @"fireperf";
  23. static NSString *const FIRDefaultFIRAppName = @"__FIRAPP_DEFAULT";
  24. static NSString *const FIRSecondFIRAppName = @"secondFIRApp";
  25. @interface FIRRemoteConfig (Sample)
  26. + (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace
  27. app:(FIRApp *)app;
  28. @end
  29. @interface ViewController ()
  30. @property(nonatomic, strong) IBOutlet UIButton *fetchButton;
  31. @property(nonatomic, strong) IBOutlet UIButton *applyButton;
  32. @property(nonatomic, strong) IBOutlet UIButton *refreshButton;
  33. @property(nonatomic, strong) IBOutlet UIButton *clearLogsButton;
  34. @property(nonatomic, strong) IBOutlet UITextView *mainTextView;
  35. /// Key of custom variable to be added by user.
  36. @property(nonatomic, weak) IBOutlet UITextField *keyLabel;
  37. /// Value of custom variable to be added by user.
  38. @property(nonatomic, weak) IBOutlet UITextField *valueLabel;
  39. /// Expiration in seconds to be set by user.
  40. @property(nonatomic, weak) IBOutlet UITextField *expirationLabel;
  41. /// Config Defaults.
  42. @property(nonatomic, strong) NSMutableDictionary *configDefaults;
  43. /// developer mode switch.
  44. @property(strong, nonatomic) IBOutlet UISwitch *developerModeEnabled;
  45. /// Current selected namespace.
  46. @property(nonatomic, copy) NSString *currentNamespace;
  47. /// Curret selected FIRApp instance name.
  48. @property(nonatomic, copy) NSString *FIRAppName;
  49. /// Selected namespace picker control view.
  50. @property(nonatomic, strong) IBOutlet UIPickerView *namespacePicker;
  51. /// Selected app picker control view.
  52. @property(nonatomic, strong) IBOutlet UIPickerView *appPicker;
  53. /// Array of prepopulated namespaces supported by this app.
  54. @property(nonatomic, strong) NSArray<NSString *> *namespacePickerData;
  55. /// Array of prepopulated FIRApp names supported by this app.
  56. @property(nonatomic, strong) NSArray<NSString *> *appPickerData;
  57. /// Array of Remote Config instances.
  58. @property(nonatomic, strong) NSMutableDictionary *RCInstances;
  59. @end
  60. @implementation ViewController
  61. - (void)viewDidLoad {
  62. [super viewDidLoad];
  63. [[FRCLog sharedInstance] setLogView:self.mainTextView];
  64. [[FRCLog sharedInstance] logToConsole:@"Viewcontroller loaded"];
  65. [[FRCLog sharedInstance] logToConsole:[[NSBundle mainBundle] bundleIdentifier]];
  66. // Setup UI
  67. self.expirationLabel.text = [NSString stringWithFormat:@"0"];
  68. self.configDefaults = [[NSMutableDictionary alloc] init];
  69. self.keyLabel.delegate = self;
  70. self.valueLabel.delegate = self;
  71. self.expirationLabel.delegate = self;
  72. self.mainTextView.editable = NO;
  73. // TODO(mandard): Add support for deleting and adding namespaces in the app.
  74. self.namespacePickerData =
  75. [[NSArray alloc] initWithObjects:FIRNamespaceGoogleMobilePlatform, FIRPerfNamespace, nil];
  76. self.appPickerData =
  77. [[NSArray alloc] initWithObjects:FIRDefaultFIRAppName, FIRSecondFIRAppName, nil];
  78. self.RCInstances = [[NSMutableDictionary alloc] init];
  79. for (NSString *namespaceString in self.namespacePickerData) {
  80. for (NSString *appString in self.appPickerData) {
  81. // Check for the default instance.
  82. if (!self.RCInstances[namespaceString]) {
  83. self.RCInstances[namespaceString] = [[NSMutableDictionary alloc] init];
  84. }
  85. if ([namespaceString isEqualToString:FIRNamespaceGoogleMobilePlatform] &&
  86. [appString isEqualToString:FIRDefaultFIRAppName]) {
  87. self.RCInstances[namespaceString][appString] = [FIRRemoteConfig remoteConfig];
  88. } else {
  89. FIRApp *firebaseApp = ([appString isEqualToString:FIRDefaultFIRAppName])
  90. ? [FIRApp defaultApp]
  91. : [FIRApp appNamed:appString];
  92. self.RCInstances[namespaceString][appString] =
  93. [FIRRemoteConfig remoteConfigWithFIRNamespace:namespaceString app:firebaseApp];
  94. }
  95. FIRRemoteConfigSettings *settings = [[FIRRemoteConfigSettings alloc] init];
  96. settings.fetchTimeout = 300;
  97. settings.minimumFetchInterval = 300;
  98. ((FIRRemoteConfig *)(self.RCInstances[namespaceString][appString])).configSettings = settings;
  99. }
  100. }
  101. /// UI popup for Realtime that shows if realtime_test_key was included in update.
  102. UIAlertController *alert = [UIAlertController
  103. alertControllerWithTitle:@"Alert"
  104. message:@"The value for realtime_test_key has been updated!"
  105. preferredStyle:UIAlertControllerStyleAlert];
  106. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK"
  107. style:UIAlertActionStyleDefault
  108. handler:^(UIAlertAction *action){
  109. }];
  110. [alert addAction:defaultAction];
  111. // Add realtime listener for firebase namespace
  112. [self.RCInstances[FIRNamespaceGoogleMobilePlatform][FIRDefaultFIRAppName]
  113. addOnConfigUpdateListener:^(FIRRemoteConfigUpdate *_Nullable update,
  114. NSError *_Nullable error) {
  115. if (error != nil) {
  116. [[FRCLog sharedInstance]
  117. logToConsole:[NSString
  118. stringWithFormat:@"Realtime Error: %@", error.localizedDescription]];
  119. } else {
  120. [[FRCLog sharedInstance] logToConsole:[NSString stringWithFormat:@"Config updated!"]];
  121. if (update != nil) {
  122. /// UI popup that lets user know that fetch included realtime_test_key in updatedKeys.
  123. if ([[update updatedKeys] containsObject:@"realtime_test_key"]) {
  124. [self presentViewController:alert animated:YES completion:nil];
  125. }
  126. NSString *updatedParams = [update updatedKeys];
  127. [[FRCLog sharedInstance]
  128. logToConsole:[NSString stringWithFormat:[updatedParams description]]];
  129. [self apply];
  130. }
  131. }
  132. }];
  133. [[FRCLog sharedInstance] logToConsole:@"RC instances inited"];
  134. self.namespacePicker.dataSource = self;
  135. self.namespacePicker.delegate = self;
  136. self.appPicker.dataSource = self;
  137. self.appPicker.delegate = self;
  138. [self.developerModeEnabled setOn:true animated:false];
  139. }
  140. - (IBAction)fetchButtonPressed:(id)sender {
  141. [[FRCLog sharedInstance] logToConsole:@"Fetch button pressed"];
  142. // fetchConfig api callback, this is triggered when client receives response from server
  143. ViewController *__weak weakSelf = self;
  144. FIRRemoteConfigFetchCompletion completion = ^(FIRRemoteConfigFetchStatus status, NSError *error) {
  145. ViewController *strongSelf = weakSelf;
  146. if (!strongSelf) {
  147. return;
  148. }
  149. [[FRCLog sharedInstance]
  150. logToConsole:[NSString stringWithFormat:@"Fetch completed. Status=%@",
  151. [strongSelf statusString:status]]];
  152. if (error) {
  153. [[FRCLog sharedInstance] logToConsole:[NSString stringWithFormat:@"Fetch Error=%@", error]];
  154. }
  155. NSMutableString *output = [NSMutableString
  156. stringWithFormat:@"Fetch status : %@.\n\n", [strongSelf statusString:status]];
  157. if (error) {
  158. [output appendFormat:@"%@\n", error];
  159. }
  160. if (status == FIRRemoteConfigFetchStatusFailure) {
  161. [output appendString:[NSString stringWithFormat:@"Fetch Error :%@.\n",
  162. [strongSelf errorString:error.code]]];
  163. if (error.code == FIRRemoteConfigErrorThrottled) {
  164. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  165. NSNumber *throttledTime =
  166. (NSNumber *)error.userInfo[FIRRemoteConfigThrottledEndTimeInSecondsKey];
  167. NSDate *date = [NSDate dateWithTimeIntervalSince1970:[throttledTime doubleValue]];
  168. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  169. NSString *timeString = [dateFormatter stringFromDate:date];
  170. [output appendString:[NSString stringWithFormat:@"Throttled end at: %@ \n", timeString]];
  171. }
  172. }
  173. [[FRCLog sharedInstance] logToConsole:output];
  174. };
  175. // fetchConfig api call
  176. [[FRCLog sharedInstance] logToConsole:@"Calling fetchWithExpirationDuration.."];
  177. [self.RCInstances[self.currentNamespace][self.FIRAppName]
  178. fetchWithExpirationDuration:self.expirationLabel.text.integerValue
  179. completionHandler:completion];
  180. }
  181. - (IBAction)fetchAndActivateButtonPressed:(id)sender {
  182. // fetchConfig api callback, this is triggered when client receives response from server
  183. ViewController *__weak weakSelf = self;
  184. FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion = ^(
  185. FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
  186. ViewController *strongSelf = weakSelf;
  187. if (!strongSelf) {
  188. return;
  189. }
  190. NSMutableString *output = [@"Fetch and activate status :" mutableCopy];
  191. if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote) {
  192. [output appendString:@"Success from remote fetch."];
  193. } else if (status == FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData) {
  194. [output appendString:@"Success using pre-fetched data."];
  195. } else if (status == FIRRemoteConfigFetchAndActivateStatusError) {
  196. [output
  197. appendString:[NSString stringWithFormat:@"Failure: %@", [error localizedDescription]]];
  198. }
  199. if (error) {
  200. [output appendFormat:@"%@\n", error];
  201. }
  202. if (status == FIRRemoteConfigFetchAndActivateStatusError) {
  203. [output appendString:[NSString stringWithFormat:@"Fetch And Activate Error :%@.\n",
  204. [strongSelf errorString:error.code]]];
  205. if (error.code == FIRRemoteConfigErrorThrottled) {
  206. [output appendString:[NSString stringWithFormat:@"Throttled.\n"]];
  207. }
  208. }
  209. // activate status
  210. [[FRCLog sharedInstance] logToConsole:output];
  211. if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote ||
  212. status == FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData) {
  213. [strongSelf printResult:[[NSMutableString alloc] init]];
  214. }
  215. };
  216. // fetchConfig api call
  217. [self.RCInstances[self.currentNamespace][self.FIRAppName]
  218. fetchAndActivateWithCompletionHandler:fetchAndActivateCompletion];
  219. }
  220. - (IBAction)activateButtonPressed:(id)sender {
  221. [self apply];
  222. }
  223. - (IBAction)refreshButtonPressed:(id)sender {
  224. NSMutableString *output = [[NSMutableString alloc] init];
  225. [self printResult:output];
  226. }
  227. - (IBAction)setDefaultFromPlistButtonPressed:(id)sender {
  228. [self.RCInstances[self.currentNamespace][self.FIRAppName]
  229. setDefaultsFromPlistFileName:@"Defaults"];
  230. [self printDefaultConfigs];
  231. }
  232. - (IBAction)setDefaultButtonPressed:(id)sender {
  233. if (self.configDefaults.count) {
  234. [self.RCInstances[self.currentNamespace][self.FIRAppName] setDefaults:self.configDefaults];
  235. [self.configDefaults removeAllObjects];
  236. [self printDefaultConfigs];
  237. } else {
  238. [[FRCLog sharedInstance] logToConsole:@"Nothing to set for defaults."];
  239. }
  240. }
  241. - (IBAction)onClearLogsButtonPressed:(id)sender {
  242. self.mainTextView.text = @"";
  243. }
  244. - (void)printDefaultConfigs {
  245. NSMutableString *output = [[NSMutableString alloc] init];
  246. [output appendString:@"\n-------Default config------\n"];
  247. NSArray<NSString *> *result = [self.RCInstances[self.currentNamespace][self.FIRAppName]
  248. allKeysFromSource:FIRRemoteConfigSourceDefault];
  249. if (result) {
  250. NSString *stringPerNs = @"";
  251. for (NSString *key in result) {
  252. FIRRemoteConfigValue *value =
  253. [self.RCInstances[self.currentNamespace][self.FIRAppName] defaultValueForKey:key];
  254. stringPerNs = [NSString stringWithFormat:@"%@%@ : %@ : %@\n", stringPerNs,
  255. self.currentNamespace, key, value.stringValue];
  256. }
  257. [output appendString:stringPerNs];
  258. }
  259. [[FRCLog sharedInstance] logToConsole:output];
  260. }
  261. - (IBAction)getValueButtonPressed:(id)sender {
  262. [[FRCLog sharedInstance] logToConsole:[self.RCInstances[self.currentNamespace][self.FIRAppName]
  263. configValueForKey:self.keyLabel.text]
  264. .debugDescription];
  265. }
  266. - (IBAction)logValueButtonPressed:(id)sender {
  267. [[FRCLog sharedInstance]
  268. logToConsole:[NSString stringWithFormat:@"key: %@ logged", self.keyLabel.text]];
  269. }
  270. // add default variable button pressed
  271. - (IBAction)addButtonPressed:(id)sender {
  272. [self addNewEntryToVariables:self.configDefaults isDefaults:YES];
  273. }
  274. - (IBAction)developerModeSwitched:(id)sender {
  275. FIRRemoteConfigSettings *configSettings = [[FIRRemoteConfigSettings alloc] init];
  276. ((FIRRemoteConfig *)(self.RCInstances[self.currentNamespace][self.FIRAppName])).configSettings =
  277. configSettings;
  278. }
  279. - (void)addNewEntryToVariables:(NSMutableDictionary *)variables isDefaults:(BOOL)isDefaults {
  280. if ([self.keyLabel.text length]) {
  281. variables[self.keyLabel.text] = self.valueLabel.text;
  282. NSString *showText = @"custom variables ";
  283. if (isDefaults) {
  284. showText = @"config defaults";
  285. }
  286. [[FRCLog sharedInstance]
  287. logToConsole:[NSString stringWithFormat:@"New %@ added %@ : %@\n", showText,
  288. self.keyLabel.text, self.valueLabel.text]];
  289. self.keyLabel.text = @"";
  290. self.valueLabel.text = @"";
  291. }
  292. }
  293. - (void)apply {
  294. [self.RCInstances[self.currentNamespace][self.FIRAppName]
  295. activateWithCompletion:^(BOOL changed, NSError *_Nullable error) {
  296. NSMutableString *output = [[NSMutableString alloc] init];
  297. [output appendString:[NSString stringWithFormat:@"ActivateFetched = %@\n",
  298. changed ? @"YES" : @"NO"]];
  299. [[FRCLog sharedInstance] logToConsole:output];
  300. if (!error) {
  301. [self printResult:output];
  302. } else {
  303. [self printResult:[[NSString stringWithFormat:@"Activate failed. Error: %@",
  304. error.localizedDescription] mutableCopy]];
  305. }
  306. }];
  307. }
  308. // print out fetch result
  309. - (void)printResult:(NSMutableString *)output {
  310. FIRRemoteConfig *currentRCInstance = self.RCInstances[self.currentNamespace][self.FIRAppName];
  311. NSString *namespace_p = self.currentNamespace;
  312. [output appendString:@"-------Active config------\n"];
  313. NSArray<NSString *> *result = [self.RCInstances[self.currentNamespace][self.FIRAppName]
  314. allKeysFromSource:FIRRemoteConfigSourceRemote];
  315. if (result) {
  316. NSString *stringPerNs = @"";
  317. for (NSString *key in result) {
  318. FIRRemoteConfigValue *value = [currentRCInstance configValueForKey:key];
  319. stringPerNs = [NSString
  320. stringWithFormat:@"%@%@ : %@ : %@\n", stringPerNs, namespace_p, key, value.stringValue];
  321. }
  322. [output appendString:stringPerNs];
  323. }
  324. [output appendString:@"\n-------Default config------\n"];
  325. result = [currentRCInstance allKeysFromSource:FIRRemoteConfigSourceDefault];
  326. if (result) {
  327. NSString *stringPerNs = @"";
  328. for (NSString *key in result) {
  329. FIRRemoteConfigValue *value = [currentRCInstance defaultValueForKey:key];
  330. stringPerNs = [NSString
  331. stringWithFormat:@"%@%@ : %@ : %@\n", stringPerNs, namespace_p, key, value.stringValue];
  332. }
  333. [output appendString:stringPerNs];
  334. }
  335. [output appendString:@"\n--------Custom Variables--------\n"];
  336. [output appendString:@"\n----------Last fetch time----------------\n"];
  337. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  338. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  339. [output
  340. appendString:[NSString stringWithFormat:@"%@\n",
  341. [dateFormatter
  342. stringFromDate:currentRCInstance.lastFetchTime]]];
  343. [output appendString:@"\n-----------Last fetch status------------\n"];
  344. [output appendString:[NSString
  345. stringWithFormat:@"%@\n",
  346. [self statusString:currentRCInstance.lastFetchStatus]]];
  347. FIRInstallations *installations = [FIRInstallations installations];
  348. [installations installationIDWithCompletion:^(NSString *_Nullable identifier,
  349. NSError *_Nullable error) {
  350. [output appendString:@"\n-----------Installation ID------------------\n"];
  351. [output appendString:[NSString stringWithFormat:@"%@\n", identifier]];
  352. [output appendString:@"\n-----------Installation ID token------------\n"];
  353. [installations authTokenWithCompletion:^(FIRInstallationsAuthTokenResult *_Nullable tokenResult,
  354. NSError *_Nullable error) {
  355. [output appendString:[NSString stringWithFormat:@"%@\n", tokenResult.authToken]];
  356. [[FRCLog sharedInstance] logToConsole:output];
  357. }];
  358. }];
  359. }
  360. - (BOOL)textFieldShouldReturn:(UITextField *)textField {
  361. [textField resignFirstResponder];
  362. return YES;
  363. }
  364. - (NSString *)statusString:(FIRRemoteConfigFetchStatus)status {
  365. switch (status) {
  366. case FIRRemoteConfigFetchStatusSuccess:
  367. return @"Success";
  368. case FIRRemoteConfigFetchStatusNoFetchYet:
  369. return @"NotFetchYet";
  370. case FIRRemoteConfigFetchStatusFailure:
  371. return @"Failure";
  372. case FIRRemoteConfigFetchStatusThrottled:
  373. return @"Throttled";
  374. default:
  375. return @"Unknown";
  376. }
  377. return @"";
  378. }
  379. - (NSString *)errorString:(FIRRemoteConfigError)error {
  380. switch (error) {
  381. case FIRRemoteConfigErrorInternalError:
  382. return @"Internal Error";
  383. case FIRRemoteConfigErrorUnknown:
  384. return @"Unknown Error";
  385. case FIRRemoteConfigErrorThrottled:
  386. return @"Throttled";
  387. default:
  388. return @"unknown";
  389. }
  390. return @"";
  391. }
  392. - (IBAction)fetchIIDButtonClicked:(id)sender {
  393. FIRInstallations *installations =
  394. [FIRInstallations installationsWithApp:[FIRApp appNamed:self.FIRAppName]];
  395. [installations installationIDWithCompletion:^(NSString *_Nullable identifier,
  396. NSError *_Nullable error) {
  397. if (error) {
  398. [[FRCLog sharedInstance] logToConsole:[NSString stringWithFormat:@"%@", error]];
  399. } else {
  400. [installations authTokenWithCompletion:^(
  401. FIRInstallationsAuthTokenResult *_Nullable tokenResult,
  402. NSError *_Nullable error) {
  403. if (tokenResult.authToken) {
  404. ((FIRRemoteConfig *)self.RCInstances[self.currentNamespace][self.FIRAppName])
  405. .settings.configInstallationsToken = tokenResult.authToken;
  406. [[FRCLog sharedInstance]
  407. logToConsole:[NSString
  408. stringWithFormat:
  409. @"Successfully got installation ID : \n\n%@\n\nToken : \n\n%@\n",
  410. identifier, tokenResult.authToken]];
  411. }
  412. }];
  413. }
  414. }];
  415. }
  416. - (IBAction)searchButtonClicked:(id)sender {
  417. NSString *output = @"-------Active Config------\n";
  418. for (NSString *key in [self.RCInstances[self.currentNamespace][self.FIRAppName]
  419. keysWithPrefix:self.keyLabel.text]) {
  420. FIRRemoteConfigValue *value =
  421. ((FIRRemoteConfig *)(self.RCInstances[self.currentNamespace][self.FIRAppName]))[key];
  422. output = [NSString stringWithFormat:@"%@%@ : %@ : %@\n", output, self.currentNamespace, key,
  423. value.stringValue];
  424. }
  425. [[FRCLog sharedInstance] logToConsole:output];
  426. }
  427. - (IBAction)userPropertyButtonClicked:(id)sender {
  428. [FIRAnalytics setUserPropertyString:self.valueLabel.text forName:self.keyLabel.text];
  429. NSString *output = [NSString
  430. stringWithFormat:@"Set User Property => %@ : %@\n", self.keyLabel.text, self.valueLabel.text];
  431. [[FRCLog sharedInstance] logToConsole:output];
  432. }
  433. #pragma mark - picker
  434. // The number of columns of data
  435. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
  436. // App and currentNamespace pickers.
  437. return 2;
  438. }
  439. // The number of rows of data
  440. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  441. NSInteger rowCount = (component == 0) ? self.namespacePickerData.count : self.appPickerData.count;
  442. return rowCount;
  443. }
  444. // The data to return for the row and component (column) that's being passed in
  445. - (NSString *)pickerView:(UIPickerView *)pickerView
  446. titleForRow:(NSInteger)row
  447. forComponent:(NSInteger)component {
  448. if (component == 0) {
  449. self.currentNamespace = self.namespacePickerData[row];
  450. return self.namespacePickerData[row];
  451. } else {
  452. self.FIRAppName = self.appPickerData[row];
  453. return self.appPickerData[row];
  454. }
  455. }
  456. - (UIView *)pickerView:(UIPickerView *)pickerView
  457. viewForRow:(NSInteger)row
  458. forComponent:(NSInteger)component
  459. reusingView:(UIView *)view {
  460. UILabel *tView = (UILabel *)view;
  461. if (!tView) {
  462. tView = [[UILabel alloc] init];
  463. [tView setFont:[UIFont fontWithName:@"Helvetica" size:15]];
  464. tView.numberOfLines = 3;
  465. }
  466. if (component == 0) {
  467. self.currentNamespace = self.namespacePickerData[row];
  468. tView.text = self.namespacePickerData[row];
  469. } else {
  470. self.FIRAppName = self.appPickerData[row];
  471. tView.text = self.appPickerData[row];
  472. }
  473. return tView;
  474. }
  475. @end