Skip to content

@0xced /XCDFakeCarrier.m
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Hack to choose the displayed carrier name in the iOS simulator
//
// 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
@iosdeveloper

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

@ksm

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

@0xced
Owner

It is now working on iOS 6.0 and 6.1.

@AriX

Nice job on this, great hack.

@twe4ked

Perfect, thanks for this!

@Jules2010

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

@Jules2010

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

@DaveM1

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!

@ksuther

A rough example of how to customize other parts of the status bar is available here: https://github.com/ksuther/StatusBarCustomization

@mpvosseller

Looks like this broke with iOS 8.3.

@muhammadbassio

@mpvoseller
Replace statusBarDataInfo with the below & it should work in 8.3 :)

NSDictionary *statusBarDataInfo = @{ @"^{?=[26c][64c]ii[100c]": @"fake_rawData",
                                         // use B instead of c for 64-bit
                                         @"^{?=[26B][64c]ii[100c]": @"fake_rawData" };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.