Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// Copyright (c) 2012-2013 Cédric Luthi / @0xced. All rights reserved.
//
#if TARGET_IPHONE_SIMULATOR
static const char *fakeCarrier;
#import <objc/runtime.h>
typedef struct {
char itemIsEnabled[23];
char timeString[64];
int gsmSignalStrengthRaw;
int gsmSignalStrengthBars;
char serviceString[100];
// ...
} StatusBarData;
typedef struct {
char itemIsEnabled[24];
char timeString[64];
int gsmSignalStrengthRaw;
int gsmSignalStrengthBars;
char serviceString[100];
// ...
} StatusBarData_6;
typedef struct {
char itemIsEnabled[25];
char timeString[64];
int gsmSignalStrengthRaw;
int gsmSignalStrengthBars;
char serviceString[100];
// ...
} StatusBarData_7;
@interface XCDFakeCarrier : NSObject
@end
@implementation XCDFakeCarrier
+ (void) load
{
fakeCarrier = getenv("FAKE_CARRIER");
if (!fakeCarrier)
{
NSLog(@"You must set the FAKE_CARRIER environment variable");
return;
}
BOOL __block success = NO;
Class UIStatusBarComposedData = objc_getClass("UIStatusBarComposedData");
SEL selector = NSSelectorFromString(@"rawData");
Method method = class_getInstanceMethod(UIStatusBarComposedData, selector);
NSDictionary *statusBarDataInfo = @{ @"^{?=[23c][64c]ii[100c]": @"fake_rawData",
@"^{?=[24c][64c]ii[100c]": @"fake_rawData_6",
@"^{?=[25c][64c]ii[100c]": @"fake_rawData_7" };
[statusBarDataInfo enumerateKeysAndObjectsUsingBlock:^(NSString *statusBarDataTypeEncoding, NSString *fakeSelectorString, BOOL *stop) {
if (method && [@(method_getTypeEncoding(method)) hasPrefix:statusBarDataTypeEncoding])
{
SEL fakeSelector = NSSelectorFromString(fakeSelectorString);
Method fakeMethod = class_getInstanceMethod(self, fakeSelector);
success = class_addMethod(UIStatusBarComposedData, fakeSelector, method_getImplementation(fakeMethod), method_getTypeEncoding(fakeMethod));
fakeMethod = class_getInstanceMethod(UIStatusBarComposedData, fakeSelector);
method_exchangeImplementations(method, fakeMethod);
}
}];
if (success)
NSLog(@"Using \"%s\" fake carrier", fakeCarrier);
else
NSLog(@"XCDFakeCarrier failed to initialize");
}
- (StatusBarData *) fake_rawData
{
StatusBarData *rawData = [self fake_rawData];
strlcpy(rawData->serviceString, fakeCarrier, sizeof(rawData->serviceString));
return rawData;
}
- (StatusBarData_6 *) fake_rawData_6
{
StatusBarData_6 *rawData = [self fake_rawData_6];
strlcpy(rawData->serviceString, fakeCarrier, sizeof(rawData->serviceString));
return rawData;
}
- (StatusBarData_7 *) fake_rawData_7
{
StatusBarData_7 *rawData = [self fake_rawData_7];
strlcpy(rawData->serviceString, fakeCarrier, sizeof(rawData->serviceString));
return rawData;
}
@end
#endif
@DaveM1

This comment has been minimized.

Copy link
Owner Author

commented Sep 16, 2013

Hi, This is awesome, but I can't figure out how to display the cellular bar strength and eliminate the WiFi icon. Anyone have insight? Thanks!

@ksuther

This comment has been minimized.

Copy link

commented Jan 1, 2014

See my fork: https://gist.github.com/ksuther/8211001

On iOS 7, you can set itemIsEnabled[3] to 1, gsmSignalStrengthBars to 5, and then set dataNetworkType to one of the following:

0 - GPRS
1 - E (EDGE)
2 - 3G
3 - 4G
4 - LTE
5 - Wi-Fi
6 - Personal Hotspot
7 - 1x
8 - Blank

To set dataNetworkType you'll need to fill out more of the struct from this header: https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UIStatusBarComposedData.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.