-
Notifications
You must be signed in to change notification settings - Fork 25k
Closed
Labels
Platform: iOSiOS applications.iOS applications.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
I have no idea where to add this but here is how to automate (mostly, under some conditions, your milage may vary - your network connection must be en0 etc.) changing the IP address of your machine when you want to run on the device.
- Click Your Project -> Build Phases -> Click the + -> New Run Script Phase
- Add the following code:
INFOPLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
echo "writing to $INFOPLIST"
PLISTCMD="Set :SERVER_IP $(ifconfig | grep inet\ | tail -1 | cut -d " " -f 2)"
echo -n "$INFOPLIST" | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
Next add the following to AppDelegate.m replacing the usual jsCodeLocation line:
NSString *jsBundleUrlString;
if (TARGET_IPHONE_SIMULATOR) {
jsBundleUrlString = @"http://localhost:8081/index.ios.bundle";
} else {
NSString *serverIP = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SERVER_IP"];
NSString *jsCodeUrlString = [NSString stringWithFormat:@"http://%@:8081/index.ios.bundle", serverIP];
jsBundleUrlString = [jsCodeUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
jsCodeLocation = [NSURL URLWithString:jsBundleUrlString];
And that's it, you should now be able to switch between the simulator and a device without any thought about where you are... Let me know if this works for you.
sibelius, framallo, tomprogers, amitverma, garrettmac and 2 more
Metadata
Metadata
Assignees
Labels
Platform: iOSiOS applications.iOS applications.Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.