Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

Friday, May 08, 2015

High memory usage of Emojis on iOS

Emoji is very popular. I am making a keyboard which contains many Emojis. However, I found the memory usage of Emoji is too high. When the keyboard's memory usage is high enough, iOS will kill the keyboard immediately.  (Looks like the limit is 40mb on iOS 8.3)

The emojis are just unicode characters. Apple renders them with lovely icons, which causes the high memory usage. It's OK, because we all know icons use much memory. But the problem is after you have destroyed the view which uses Emoji, the memory of Emoji will not be released. Looks like iOS keeps the Emoji cache in the app or app extension. It's acceptable in an app, but not acceptable in an app extension.

What I have to do is to delete many emojis from my keyboard.

Friday, July 20, 2012

Can't dismiss keyboard on iPad (Solution inside)

Sometimes, you see the following code of dismissing keyboard not working on iPad but working on iPhone:

[_textField resignFirstResponder];

That's because a modal view in UIModalPresentationFormSheet mode on iPad ignores it by default.


To let it work, we need to add this method into your view controller:

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}

If your view controller is in a navigation controller, add this method into your customised navigation controller.

- (BOOL)disablesAutomaticKeyboardDismissal {
    return [self.topViewController disablesAutomaticKeyboardDismissal];
}

Can't change UITableView background colour on iPad (Solution Inside)

If your app is an universal app and you changed the background colour of an UITableView, you will see it works on iPhone but does not work on iPad.

The reason is we can't modify the background colour of the backgroundView of the tableview on iPad. (I think it is a bug. But Apple does not fix it for years.)

Solution: create a new backgroundView.

_tableView.backgroundView = nil;
_tableView.backgroundView = [[[UIView alloc] init] autorelease];
_tableView.backgroundColor = [UIColor clearColor];

Wednesday, March 14, 2012

Rebuilding Code Sense and Syntax Highlighting on Xcode 4

Sometimes syntax highlighting does not work on Xcode 4. Syntax highlighting is an important feature to developers. But there is no "Rebuild Code Sense" menu on Xcode 4. We can do it with following steps:

1. Xcode menu: Window->Organizer

2. Go to Projects tab

3. Choose your project on the left panel.

4. Click "Delete…" button after the Derived Data on the right panel.

Xcode will start to rebuild code sense of your project.

Thursday, March 08, 2012

Diff and Merge Localizable.strings in git

The default code set of Localizable.strings is UTF-16. Actually I don't care what code set it is. But git/gitX/SourceTree does not recognize UTF-16 (Stupid!). They treat UTF-16 Localizable.strings as a binary file and reject to diff or merge. This is a very big problem if you work in a team.

Google says we can make git support UTF-16. I tried, but failed. I have to convert Localizable.strings into UTF-8. (Actually before converting, I have manually merged by myself.) Surprisingly, git/SourceTree still says it is a binary file and cannot diff. It's OK. Just commit. Git says it just because the history files are still UTF-16. If you make any new changes, git can diff and merge it. Great!

Thursday, February 16, 2012

Keyboard notification bug on iOS 5

When the soft keyboard appears, we need to re-arrange the UI controls. I move the control up a little bit in keyboardWillShow handler:

frame.origin.y -= CONSTANT;

control.frame = frame;

But there is an annoying bug (or behavior) about non-English language keyboard on iOS 5. If you are using English keyboard, you will receive keyboardWillShow notification once. It is good. But if you are using some language keyboard like Chinese, you will receive the same notification TWICE! That means the above code will move the control up twice.

Some non-English language keyboard has an additional line at the top, used to choose words. Sounds like that additional line causes this problem.

The solution is simple. Just use hard-coded positions. And the additional line on some non-English language keyboards may cover parts of your UI on iOS 5. You have to leave enough space for keyboards. If your textField requires English characters only, you can force the keyboard to show English:

textField.keyboardType = UIKeyboardTypeASCIICapable;

Tuesday, October 18, 2011

Let Several Apps Use the same Facebook App ID

If you want to let your user post something from your app onto Facebook, you need to register a Facebook app and call Facebook SDK to post messages. But if you have a free version and a paid version, you would like to share the same Facebook App ID.

Just follow Facebook tutorial to register Facebook App and config your apps. https://developers.facebook.com/docs/mobile/ios/build/

The only one thing I need to mention is you must leave 'iOS Bundle ID' empty.

From Facebook doc page:

iOS Bundle ID - (Optional) You may set this to match the bundle ID for your iOS app. If you add this setting then the bundle ID of your app will be checked before authorizing the user. The benefit of this setting for SSO is if the user has already authorized your app they will not be asked to authorize it when they access your app from a new device.

Sunday, October 09, 2011

Xcode 4 and Git

I am new to Git. I used Perforce (P4) before, so I thought it is easy to use Git. Actually I was wrong. Git is not complex, but it has different concept.

In P4, we just check out and check in files. In Git, checking in has a new name Commit. When I committed my first change, I was surprised to see it does not appear in the server. Actually, Git did not really submit my code to the server. It was stored locally. I have to run this command in the command line:

git push origin master

So you must Push the local Commits to the server.

The problem is Xcode 4 can Pull, Commit, Compare, but does not provide Push functionality. How stupid the designer is. You can modify but cannot submit! Actually Pull, Commit and Compare are the only functionalities Xcode 4 provides. You cannot even revert!

Xcode 4 is free, but Apple should not make it suck.

Update on Nov 30, 2011:

SourceTree on Mac App Store is an excellent Git client. It is much better than GitX. And it is FREE!

Thursday, September 29, 2011

Why Use Cocos2D Instead of UIKit to Develop Games

I am leaning Cocos2D for iPhone. I am thinking why we should use cocos2D instead of UIKit to develop games.

Here are the reasons:

1. Cocos2D is built on OpenGL. You may not know OpenGL.

2. Cocos2D supports tiled map.

3. Cocos2D helps you reduce memory cost by supporting atlas images and providing CCSpriteBatchNode.

4. Cocos2D supports parallax backgrounds.

5. Cocos2D has more animations and transitions.

6. Cocos2D supports particle systems.

Cocos2D provides physics engines, but I don't think it is one of the reasons we should use Cocos2D. Because these physics engines are not designed for Cocos2D only. If you use UIKit, you can use these physics engines too.

Monday, July 18, 2011

Decreasing the iPhone/iPad app size

1. Delete unnecessary files.

2. Convert PNG images to JPG format. We like PNG because it supports transparency. But for those images without transparency, the size of png is twice of jpg file. I converted PNG files to JPG and reduced the app size from 17MB to 9MB.

3. For the universal app, iPad version could reuse retina @2x images.

The way to stop UIView animations

#import <QuartzCore/QuartzCore.h>

[self.view.layer removeAllAnimations];

Adding a framework in Xcode 4

The steps of adding a framework in Xcode 4:

1. Click current project in Project navigator.

2. Click a target in Project editor.

3. Choose Build Phases tab.

4. Expand Link Binary With Libraries

5. Click + button, add a framework.

6. Go back to Project navigator. You will see the new framework added. You can drag it into Framework group. If you have more than one target, you need not repeat the steps for other target. Just choose this framework in Project navigator, and make selection in Target Membership in File Inspector on the right Utility window of Xcode.

What's New in iOS 5 sdk

The key developer-related features introduced in iOS 5.0 (Official doc):

1. iCloud

2. Storyboard

Storyboard is not xib. "A storyboard file captures your entire user interface in one place and lets you define both the individual view controllers and the transitions between those view controllers." I think It sounds like Keynote or Powerpoint. You can design every page's content and the transition between pages.

3. Newsstand (for magazines and newspapers)

4. New Frameworks

- GLKit (Game Library Kit?). The GLKit framework (GLKit.framework) contains a set of Objective-C based utility classes that simplify the effort required to create an OpenGL ES 2.0 application.

- Core Image. A powerful set of built-in filters for manipulating video and still images, such as touching up, correcting photos, face and feature detection.

- Twitter.

- Accounts. A single sign-on model for certain user accounts. Apps can use it to access twitter account.

- Generic Security Services.

5. Automatic Reference Counting (ARC).

Actually, it is a new feature of the language and the compiler. It helps you manage the objects lifetime and memory. There are some restrictions to use ARC:

1. You don't need to (and are not allowed to) call retain/release/autorelease.

2. You don't need to (but can) implement your dealloc method.

3. You can't use NSAutoreleasePool objects. Actually, they are replaced by @autoreleasepool keyword.

3. You can't define object points in C structures.

4. You can't directly cast between object and nonobject types (for example, between id and void*).

For more information about ARC itself, see Programming With ARC.