Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Recreating the UIStatusBarItemType enum
//
// statusbartypes
//
// Created by Leptos on 3/19/19.
// Copyright © 2019 Leptos. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef int UIStatusBarItemType;
API_AVAILABLE(ios(4.0))
@interface UIStatusBarItem : NSObject
@property (nonatomic, readonly) Class viewClass API_AVAILABLE(ios(6.0));
@property (nonatomic, readonly) NSString *indicatorName API_AVAILABLE(ios(6.0));
+ (BOOL)typeIsValid:(UIStatusBarItemType)type;
+ (instancetype)itemWithType:(UIStatusBarItemType)type idiom:(UIUserInterfaceIdiom)idiom API_AVAILABLE(ios(7.0));
@end
int main() {
// in newer SDKs, UIStatusBarItem (and other private UIKit symbols) are missing from the UIKit tbd
Class const UIStatusBarItemClass = NSClassFromString(@"UIStatusBarItem");
UIUserInterfaceIdiom const idiom = UIDevice.currentDevice.userInterfaceIdiom;
/* the name of viewClass typically conforms to the name scheme "UIStatusBar\(Identifier)ItemView" */
NSString *const classPrefix = @"UIStatusBar", *const classSuffix = @"ItemView";
NSUInteger const totalTrimLength = classSuffix.length + classPrefix.length;
// print device info
printf("/* %s %s */\n",
UIDevice.currentDevice.systemName.UTF8String,
NSProcessInfo.processInfo.operatingSystemVersionString.UTF8String);
puts("typedef enum {");
for (UIStatusBarItemType type = 0; [UIStatusBarItemClass typeIsValid:type]; type++) {
UIStatusBarItem *item = [UIStatusBarItemClass itemWithType:type idiom:idiom];
Class itemClass = item.viewClass;
NSString *indicatorName = item.indicatorName;
if (itemClass == nil) {
printf(" /* %d skipped */\n", type);
continue;
}
NSString *targetName = NSStringFromClass(itemClass);
if (![targetName hasPrefix:classPrefix]) {
NSLog(@"Warning: %d does not have expected prefix (%@)", type, targetName);
}
if (![targetName hasSuffix:classSuffix]) {
NSLog(@"Warning: %d does not have expected suffix (%@)", type, targetName);
}
targetName = [targetName substringWithRange:NSMakeRange(classPrefix.length, targetName.length - totalTrimLength)];
if (indicatorName) {
targetName = [targetName stringByAppendingString:indicatorName];
}
printf(" UIStatusBarItemType%s = %d,\n", targetName.UTF8String, type);
}
puts("} UIStatusBarItemType;");
}
@leptos-null
Copy link
Author

leptos-null commented May 26, 2019

The output I got from this program, on an iOS 10.2 device, was contributed to theos/headers

@leptos-null
Copy link
Author

leptos-null commented May 26, 2019

iPhone 7, iOS 12.2 Simulator:

typedef enum {
   UIStatusBarItemTypeTime = 0,
   /* 1 skipped */
   UIStatusBarItemTypeQuietModeQuietMode = 2,
   UIStatusBarItemTypeAirplaneModeAirplane = 3,
   UIStatusBarItemTypeSignalStrength = 4,
   /* 5 skipped */
   UIStatusBarItemTypeService = 6,
   /* 7 skipped */
   UIStatusBarItemTypePersonName = 8,
   UIStatusBarItemTypeDataNetwork = 9,
   /* 10 skipped */
   UIStatusBarItemTypeTime = 11,
   UIStatusBarItemTypeBattery = 12,
   UIStatusBarItemTypeBatteryPercent = 13,
   UIStatusBarItemTypeNotCharging = 14,
   UIStatusBarItemTypeBluetoothBattery = 15,
   UIStatusBarItemTypeBluetooth = 16,
   UIStatusBarItemTypeIndicatorTTY = 17,
   UIStatusBarItemTypeIndicatorAlarm = 18,
   UIStatusBarItemTypeIndicatorPlus = 19,
   UIStatusBarItemTypeIndicator = 20,
   UIStatusBarItemTypeLocation = 21,
   UIStatusBarItemTypeIndicatorRotationLock = 22,
   UIStatusBarItemTypeDoubleHeightDoubleHeight = 23,
   UIStatusBarItemTypeIndicatorAirPlay = 24,
   UIStatusBarItemTypeIndicatorSiri = 25,
   UIStatusBarItemTypeCarPlayCarPlay = 26,
   UIStatusBarItemTypeStudentStudent = 27,
   UIStatusBarItemTypeIndicatorVPN = 28,
   UIStatusBarItemTypeIndicatorCallForward = 29,
   /* 30 skipped */
   UIStatusBarItemTypeActivity = 31,
   UIStatusBarItemTypeThermalColor = 32,
   UIStatusBarItemTypeRadar = 33,
   UIStatusBarItemTypeElectronicTollCollection = 34,
   UIStatusBarItemTypeCarPlayDock = 35,
   UIStatusBarItemTypeCarPlayDock = 36,
   UIStatusBarItemTypeLock = 37,
   UIStatusBarItemTypeLiquidDetection = 38,
   UIStatusBarItemTypeIndicatorBTHeadphones = 39,
   /* 40 skipped */
   UIStatusBarItemTypeHome = 41,
   UIStatusBarItemTypeReturnToCall = 42,
   UIStatusBarItemTypeNavigation = 43,
   UIStatusBarItemTypeTethering = 44,
   UIStatusBarItemTypeBreadcrumb = 45,
   UIStatusBarItemTypeOpenInSafari = 46
} UIStatusBarItemType;

@leptos-null
Copy link
Author

leptos-null commented May 26, 2019

iPhone 7, iOS 11.3 Simulator:

typedef enum {
    UIStatusBarItemTypeTime = 0,
    UIStatusBarItemTypeQuietModeQuietMode = 1,
    UIStatusBarItemTypeAirplaneModeAirplane = 2,
    UIStatusBarItemTypeSignalStrength = 3,
    UIStatusBarItemTypeService = 4,
    UIStatusBarItemTypePersonName = 5,
    UIStatusBarItemTypeDataNetwork = 6,
    UIStatusBarItemTypeTime = 7,
    UIStatusBarItemTypeBattery = 8,
    UIStatusBarItemTypeBatteryPercent = 9,
    UIStatusBarItemTypeNotCharging = 10,
    UIStatusBarItemTypeBluetoothBattery = 11,
    UIStatusBarItemTypeBluetooth = 12,
    UIStatusBarItemTypeIndicatorTTY = 13,
    UIStatusBarItemTypeIndicatorAlarm = 14,
    UIStatusBarItemTypeIndicatorPlus = 15,
    UIStatusBarItemTypeIndicator = 16,
    UIStatusBarItemTypeLocation = 17,
    UIStatusBarItemTypeIndicatorRotationLock = 18,
    UIStatusBarItemTypeDoubleHeightDoubleHeight = 19,
    UIStatusBarItemTypeIndicatorAirPlay = 20,
    UIStatusBarItemTypeIndicatorSiri = 21,
    UIStatusBarItemTypeCarPlayCarPlay = 22,
    UIStatusBarItemTypeStudentStudent = 23,
    UIStatusBarItemTypeIndicatorVPN = 24,
    UIStatusBarItemTypeIndicatorCallForward = 25,
    UIStatusBarItemTypeActivity = 26,
    UIStatusBarItemTypeThermalColor = 27,
    UIStatusBarItemTypeRadar = 28,
    UIStatusBarItemTypeElectronicTollCollection = 29,
    UIStatusBarItemTypeCarPlayDock = 30,
    UIStatusBarItemTypeCarPlayDock = 31,
    UIStatusBarItemTypeLock = 32,
    UIStatusBarItemTypeLiquidDetection = 33,
    UIStatusBarItemTypeIndicatorBTHeadphones = 34,
    UIStatusBarItemTypeHome = 35,
    UIStatusBarItemTypeReturnToCall = 36,
    UIStatusBarItemTypeNavigation = 37,
    UIStatusBarItemTypeTethering = 38,
    UIStatusBarItemTypeBreadcrumb = 39,
    UIStatusBarItemTypeOpenInSafari = 40
} UIStatusBarItemType;

@leptos-null
Copy link
Author

leptos-null commented May 26, 2019

iPhone 6, iOS 9.3 Simulator:

typedef enum {
    UIStatusBarItemTypeTime = 0,
    UIStatusBarItemTypeQuietModeQuietMode = 1,
    UIStatusBarItemTypeAirplaneModeAirplane = 2,
    UIStatusBarItemTypeSignalStrength = 3,
    UIStatusBarItemTypeService = 4,
    UIStatusBarItemTypePersonName = 5,
    UIStatusBarItemTypeDataNetwork = 6,
    UIStatusBarItemTypeTime = 7,
    UIStatusBarItemTypeBattery = 8,
    UIStatusBarItemTypeBatteryPercent = 9,
    UIStatusBarItemTypeNotCharging = 10,
    UIStatusBarItemTypeBluetoothBattery = 11,
    UIStatusBarItemTypeBluetooth = 12,
    UIStatusBarItemTypeIndicatorTTY = 13,
    UIStatusBarItemTypeIndicatorAlarm = 14,
    UIStatusBarItemTypeIndicatorPlus = 15,
    UIStatusBarItemTypeIndicator = 16,
    UIStatusBarItemTypeLocation = 17,
    UIStatusBarItemTypeIndicatorRotationLock = 18,
    UIStatusBarItemTypeDoubleHeightDoubleHeight = 19,
    UIStatusBarItemTypeIndicatorAirPlay = 20,
    UIStatusBarItemTypeIndicatorSiri = 21,
    UIStatusBarItemTypeIndicatorCarPlay = 22,
    UIStatusBarItemTypeIndicatorStudent = 23,
    UIStatusBarItemTypeIndicatorVPN = 24,
    UIStatusBarItemTypeIndicatorCallForward = 25,
    UIStatusBarItemTypeActivity = 26,
    UIStatusBarItemTypeThermalColor = 27,
    UIStatusBarItemTypeRadar = 28,
    UIStatusBarItemTypeHome = 29,
    UIStatusBarItemTypeReturnToCall = 30,
    UIStatusBarItemTypeNavigation = 31,
    UIStatusBarItemTypeMapsCompass = 32,
    UIStatusBarItemTypeTethering = 33,
    UIStatusBarItemTypeBreadcrumb = 34,
    UIStatusBarItemTypeOpenInSafari = 35
} UIStatusBarItemType;

@leptos-null
Copy link
Author

leptos-null commented May 26, 2019

Doesn't look like an ABI stable enum.

@kirb should this be removed from theos/headers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment