[Quickies]Getting UITextView to dismiss keyboard when the user hits the return key

No Comments

It might seem something simple, but I still remember when I was beginning my life as an iOS developer and certain things were not exactly out of the box. UITextView’s support for multiple lines puts it into a complicate situation when it comes to handle the return key. Still, that’s something you can easily implement using a delegate method.

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if([text isEqualToString:@”\n”]){

[textView resignFirstResponder];

return NO;
}
return YES;

}

Using native Objective-C code from UIWebView

No Comments

There are many of frameworks out there like PhoneGap that allow you to write iOS apps using HTML and Javascript. Even if you know Objective-C and/or SWIFT, sometimes a UIWebView might be useful. But what if you need to use functionality that’s not available on webkit? Creating a bridge between Javascript and Objective-C is easier than you think!

Open Xcode and create a new project.

Screen Shot 2015-05-23 at 5.16.03 AM

More

[Quickies]Making an iPhone vibrate

No Comments

Making an iPhone vibrate is very easy and takes only one function. The first thing you have to do is to import the AudioToolbox framework into your project and header file(s). That framework provides two functions you can use:

AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

When the device does not support vibration(e.g. an iPod touch), the device will beep instead of vibrating. If it supports vibration, it will vibrate.

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

This function will vibrate a device that supports vibration. If the device doesn’t support it, it will do nothing.

Adding an external library on Android Studio

No Comments

When I started writing Android apps, I(just like everyone else) used Eclipse. Then Google released Android Studio, a whole new IDE designed for Android development. Things are obviously different from Eclipse. One of my first questions was “How do I import a library into my project?”. It turns out to be very easy!

To import a library click on File > Project structure.

More

I’m on GitHub

No Comments

It toke a while to convince me to start using GitHub, but a few days ago a friend finally convinced me. I already published a few projects there and intend to publish a lot more. I will stop publishing open source projects on this blog(at least for now). Anyway, go check it out!

FVGetApp, an open source class to get and set default apps

No Comments

I’m pleased to announce the release of FVGetApp, an open source class to get and set default apps on Mac OS X. Say your Cocoa app needs to change the default browser. Not only FVGetApp can change it, but it also can get a list of apps that can handle the HTTP protocol. FVGetApp’s not limited to HTTP and HTTPS. It’s also possible to deal with any other protocol like mailto, ichat and ftp.

You can also deal with MIME types and extensions. So if you created an audio player and you want to let the user change the default app for MP3 files with a click, you will like my class too.

As a plus you can also check if an app can open a certain file.

I developed and tested it on Mountain Lion, but it should work on previous versions of Mac OS X. Adapting it to non-ARC code would take less than 1 minute. You can download a ZIP file containing the class, documentation and a test app by clicking here. To help you to understand the capabilities of this class before downloading the ZIP, here’s a method list:

+(BOOL)isAppCompatible:(NSURL *)appURL withFile:(NSURL *)fileURL;
+(NSDictionary *)appForProtocol:(NSString *)protocol;
+(NSDictionary *)appForMIMEType:(NSString *)MIMEType;
+(NSDictionary *)appForExtension:(NSString *)extension;
+(NSArray *)allAppsForProtocol:(NSString *)protocol;
+(NSArray *)allAppsForMIMEType:(NSString *)MIMEType;
+(NSArray *)allAppsForExtension:(NSString *)extension;

Busy busy busy

No Comments

Currently I’m busy as hell. I’m working on a new Mac app and I hope to finish it soon. Working 10˜12 hours a day is painful!

Android

No Comments

Galaxy Tab 7.0 Plus

Galaxy Tab 7.0 Plus

 

Developing for Android is not a choice anymore. A lot of my customers are asking for Android apps, so I bought this nice piece of gadget. I need a real device because Android simulator is just too slow and doesn’t seem to work very well. Time to learn how to program for Android!

[Open Source]FVGravityView

No Comments

Hey folks, I’m proud to announce my new open source project for iPhone. It’s called FVGravityView. It’s basically an UIView that has the ability to fall. Yes, fall. It uses the accelerometer to detect the device position and the view will fall depending on it. It’s basically an UIView that recognizes gravity.

A few thing:
-The default velocity is 20, but you may change this value by changing the velocity property.
-FVGravityView supports dragging. To enable it, set the property isDragable to YES.
-Say you want to invert the gravity. Just set the isInverse to YES.
-It’s basically an UIView, so you may add subviews to it. It also has every drawing capabilities that an ordinary UIView has.

To download the sample project, click here.

PS: I didn’t try it on an iPad, but it should work with no problems at all.

Easy multithreading, a courtesy of NSOperation

No Comments

Threading is known for being very hard in any language. A foolish mistake can make your application crash. Programmers spend a lot of time to make sure everything works fine. On Mac OS X 10.5, Apple finally introduced a very easy way to deal with threading. NSOperation is The Apple Way® to deal with threading. All you have to do is to subclass the NSOperation, create and initialize a NSOperationQueue, create and initialize the NSOperation and add it to the NSOperationQueue. For this tutorial, I will teach you how to write a simple app that will load a RSS feed and display it on a NSTableView.

To get started, go to Xcode and create a new project. I will call mine RSS Reader, but feel free to call it whatever you want. Let’s start by editing our AppDelegate.h. Create 3 IBOutlets:

More

Older Entries