Tuesday, 19 August 2014

build the iphone simulator build to check on some else simulator

Generate a Simulator Build

In order to generate a simulator build you will:
  • Find the folder containing your xcode project.
  • Open a terminal and run a couple of commands to generate the build.
  • Compress the simulator build into a zip file.

Find your Xcode project directory

Start or run iPhone Simulator using terminal

Assuming you have Xcode installed in `/Applications`, then you can do this from the command line to start the iPhone Simulator:

    $ open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app

You could create a symbolic-link from your Desktop to make this easier:

    $ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app ~/Desktop

As pointed out by @JackHahoney, you could also add an `alias` to your `~/.bash_profile`:

    alias iphone-sim='open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/De‌​veloper/Applications/iPhone\ Simulator.app'

Which would mean you could start the iPhone Simulator from the command line with one easy-to-remember word:

    $ iphone-sim

Wednesday, 13 August 2014

Get delegate and window reference in iOS

AppDelegate *appDelegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];



UIWindow *mainWindow = [[UIApplication sharedApplication] windows].lastObject;
// or
 UIWindow *mainWindow = [(AppDelegate*) [[UIApplication sharedApplication] delegate] window];


// If UINavigationController is on the rootViewController

UINavigationController *navController = (UINavigationController*) [[appDelegate window] rootViewController];



//=====================     AppDelegate.m          ====================
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    UIStoryboard *mainStoryboard = nil;
    if (IS_IPHONE_5) {
        mainStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone5" bundle:nil];
    }
    else {
        mainStoryboard = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];
    }
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = [mainStoryboard instantiateInitialViewController];
    [self.window makeKeyAndVisible];
    return YES;
}

Repeat code in certain time peroid. periodically call a method

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [NSTimer scheduledTimerWithTimeInterval:1.0 // time in seconds
                                     target:self
                                   selector:@selector(timerFired)
                                   userInfo:nil
                                    repeats:YES];
}

- (void)timerFired{
    NSLog(@"Hello");
}