Showing posts with label ios dev. Show all posts
Showing posts with label ios dev. Show all posts

Tuesday, September 15, 2015

iOS Test Flight

To enable Test Flight:

  1. Upload a build to App Store (via XCode)
  2. Login to iTunes Connect, go to the "Pre-Release" section
  3. Enable Test Flight for the build
  4. Add users
References:

Wednesday, October 30, 2013

iOS Autorelease After Creating New Object

It is recommended to call "autorelease" after create a new object via the "new" operator (or any other method that leaves the retain count set at 1 but doesn't call "autorelease"). This is because after a "new" operator, the retain count of the object is set to "1" to ensure that it doesn't get destroyed. If "autorelease" is not called, the object will continue to take up memory until "release" is called on the object. Calling "autorelease" will ensure that the object's retain count is set to reduced by one (important!) after the current event loop is completed and the autorelease pool is drained. This means that if "retain" is called subsequently, the object will still not be destroyed if that is not matched with a corresponding "release".

Note: I ran my tests on Cocos2D-X's implementation of the autorelease pool system but as I understand, it behaves the same as the iOS one.

References:

Tuesday, October 8, 2013

Cocos2D-X Multi-Resolution Support

Guide here: http://www.cocos2d-x.org/wiki/Multi_resolution_support

Cocos2D Managing Touch Input

In a subclass of CCLayer, just set "isTouchEnabled" to true and implement the callback functions.

Otherwise, add a touch delegate class to the touch dispatcher. There are 2 types, as explained here: http://www.cocos2d-iphone.org/wiki/doku.php/tips:touchdelegates

Porting From Obj-C to C++ for Cocos2D-X

This page provides a guide for developers when porting code from Obj-C to C++

http://www.cocos2d-x.org/wiki/Moving_From_Objective-C_to_C++

Friday, January 25, 2013

iOS How to Close an App

With multi-tasking, apps no longer really close when you press the home button. It stays in the background and the OS automatically closes them when the device is low on memory and when it thinks the app is unlikely to be used in the near future. To force it to close for e.g. development testing purpose, follow the instructions on this page: http://support.apple.com/kb/ht5137

Monday, January 7, 2013

Tuesday, December 4, 2012

Cocos2D: Z Order

The higher the number, the closer the object is to the viewer.

The lower the number, the further the object is to the viewer.

Tuesday, November 6, 2012

iOS: String Format for Numbers With Leading Zeros

To obtain a formatted String with a fixed number or digits, and any shortfall padding by leading zeroes,   use the following function call


[NSString stringWithFormat:@"%04d", i];


This will return a String containing the integer "i" and will always be 4 digit long. If i is 1, then the String will be "0001". If it is 12, then the String will be "0012".

Friday, November 2, 2012

iOS: Differentiate Between iPhone and iPad

Use the function "UI_USER_INTERFACE_IDIOM()".

If what it returns is equals to "UIUserInterfaceIdiomPad", it's an iPad.

If what it returns is equals to "UIUserInterfaceIdiomPhone", it's an iPhone.

Reference: http://stackoverflow.com/questions/3905603/is-it-safe-to-check-for-ui-user-interface-idiom-to-determine-if-its-an-iphone

iOS Cocos2D Old Splash Screen Still Showing

Somehow, iOS simulators caches the loading image (e.g. Default.png), so even after you've deleted it, it still shows. In order to remove it, you'll need to do a clean operation in XCode, and also reset the simulator.

Reference: http://stackoverflow.com/questions/4768960/cant-get-rid-of-splash-screen-in-xcode

Sunday, July 15, 2012

iOS: AudioQueue Get Audio Level

A very good example of this is found in the "SpeakHere" reference project provided by Apple:
Link: http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html

Just some gotcha's and points to note:

You need to call AudioQueueSetProperty to enable the level metering feature in the first place:
UInt32 enableMetering = 1;
AudioQueueSetProperty(audioQueue, kAudioQueueProperty_EnableLevelMetering, &enableMetering, sizeof(UInt32));

The number returned by the AudioQueue will be a negative number with a maximum value of 0. To convert it to a number on a linear scale (i.e. gain level), use the following formula:
float level = pow(10., 0.05 * averagePower);

Where averagePower is the value returned by the AudioQueue for the audio level average power.

The rest should be pretty straight-forward from studying the example.

Links and References:

iOS: Making the Table Cell Background a Gradient

This is a good guide for doing it:

http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients

Thursday, July 12, 2012

iOS Activity Indicator

This is how it is done (example is using WebView)
Link: http://stackoverflow.com/questions/11334247/add-activity-indicator-to-web-view

I made some further changes so the indicator is more visible (by putting it inside an alert popup):

- (void)viewDidLoad
{
    [super viewDidLoad];    
    loadingAlert = [[UIAlertView alloc] initWithTitle:@"Loading..."
                                                      message:@"\n"
                                                     delegate:self
                                            cancelButtonTitle:nil
                                            otherButtonTitles:nil, nil];

    activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    [loadingAlert addSubview:activityIndicator];
}

- (void) showLoadingAlert
{
    [loadingAlert show];    
    activityIndicator.frame = CGRectMake((x,y,w,h);
    [activityIndicator startAnimating];
}
- (void) dismissLoadingAlert
{
    [activityIndicator stopAnimating];
    [loadingAlert dismissWithClickedButtonIndex:0 animated:NO];
}

Note that I set the frame after "show". This is because if I wanted to calculate x,y,w,h relative to the size of the loading alert frame, these values will only be non-zero after show.

NSTimer Gotchas With Threads/RunLoops

Sometimes when you notice that the NSTimer isn't working (i.e. the scheduled task doesn't fire), it can be caused by runloop issues.

By default, it runs in the current run loop from where it is scheduled. If you schedule it from the wrong loop, it might not fire as the loop could be blocked somewhere else.

Which method you use to initialize the timer also makes a difference. The "scheduledTimerWithTimeInterval" creates a timer that runs in the current loop. If the current loop is not suitable for the timer to run, the timer may not fire and you have no idea why.

If you have a problem with the above, you will have to use the "timerWithTimeInterval" methods. However, you have to remember to add the timer to the run loop that you want to add on.

For example, to schedule a timer on the main loop from another loop:

NSTimer *timer = [NSTimer timerWithTimeInterval:waiTime target:self selector:@selector(fireMethod:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]

The various behaviors are documented in the class reference.

Reference: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nstimer_Class/Reference/NSTimer.html

Wednesday, July 11, 2012

iOS: Positioning a View Relative to Parent

This is done via the "frame" property of the View, e.g.

viewObj.frame = CGRectMake(20,20,50,40);

Friday, June 15, 2012

iOS: Get Version Number of App

Do this:

NSString *lcVersionNumber = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];


Link: http://dipinkrishna.com/blog/2012/06/ios-apps-version-number-cfbundleversion/

Sunday, June 10, 2012

iOS: Uploading App "No Suitable Application Records Were Found" Gotcha

After defining the app, the status is "Prepare for Upload". At this point, it is not possible to upload yet. You'll also need click on the "Upload Binary" link, answer a question on encryption, and then the status changes to "Waiting for Upload". At this point, you can upload.