SoFunction
Updated on 2025-04-12

iOS 12 adaptation and problem notes

Preface

This article mainly introduces relevant content about iOS12 adaptation and problems. We will share it for your reference and learning. I won’t say much below. Let’s take a look at the detailed introduction together.

Version information

Xcode: Version 10.0 beta (10L176w)
macOS: 10.14 Beta (18A293u)
iOS: 12.0(16A5288q)

Problem and resolution process

1. StatusBar internal structure changes

Phenomenon: crash
crash log:
1,-[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820
2,Terminating app due to uncaught exception ‘NSInvalidArgumentException', reason: ‘-[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820'

———————————————————————————————

Problem code and solution

+ (NSString *)getIphoneXNetWorkStates { 
 UIApplication *app = [UIApplication sharedApplication];
 id statusBar = [[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"statusBar"];
 id one = [statusBar valueForKeyPath:@"regions"];
 id two = [one valueForKeyPath:@"trailing"];
 NSArray *three = [two valueForKeyPath:@"displayItems"];
 NSString *state = @"No network";
 for (UIView *view in three) {
  //alert: In iOS12.0, the identifier becomes the class "_UIStatusBarIdentifier" instead of NSString, so crash occurs when the "isEqualToString" method is called.  //Before modification//  NSString *identifier = [view valueForKeyPath:@"identifier"];
  //After modification  NSString *identifier = [[view valueForKeyPath:@"identifier"] description];
  if ([identifier isEqualToString:@"_UIStatusBarWifiItem.signalStrengthDisplayIdentifier"]) {
   id item = [view valueForKeyPath:@"_item"];

   //alert: This problem is the same as above itemId is type _UIStatusBarIdentifier, not string   NSString *itemId = [[item valueForKeyPath:@"identifier"] description];
   if ([itemId isEqualToString:@"_UIStatusBarWifiItem"]) {
    state = @"WIFI";
   }
   state = @"uncertain";

  } else if ([identifier isEqualToString:@"_UIStatusBarCellularItem.typeDisplayIdentifier"]) {
   UIView *statusBarStringView = [view valueForKeyPath:@"_view"];
   // 4G/3G/E
   state = [statusBarStringView valueForKeyPath:@"text"];
  }

 }
 return state;
}

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.