public
Last active

Hack to choose the displayed carrier name in the iOS simulator

  • Download Gist
XCDFakeCarrier.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
//
// 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

Nice for taking screenshots or recording screencasts. Does even run on device!

Doesn't work on iOS Simulator 6.0, at least for me. (Failed to initialize).

It is now working on iOS 6.0 and 6.1.

Nice job on this, great hack.

Perfect, thanks for this!

I'm getting this error ld: 2 duplicate symbols for architecture i386, any ideas>

Never mind, I ended up putting some code into a h file and imported that into my app delegate which solved the problem :)

Hi, this is awesome, but I can't figure out how to display the cellular bar strength and eliminate the WiFi signal Icon. Anyone have insight?

Thanks!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.