[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.

New iPhone

No Comments

So today I just got a new iPhone. It’s a 16GB 4S white. I really miss my old iPhone as it was the last great gift my aunt gave me before dying. Anyway, I thought the white model was way cooller, but now I see I was wrong. And this time, in case anyone finds/steals it, they will have a little surprise…

BTW, Siri is pretty cool. Too bad it won’t find restaurants and night clubs in Brazil. Now I gotta get back to work.

When things can’t get worse, they GET worse :(

No Comments

Ya know those movies where the character’s life is fucked up and they say that it cannot get worse and suddenly something bad happens? Too bad it exists outside the movies. My life is a big piece of shit since a couple months ago. Yeah, that was bad, but yesterday it got even worse. And I didn’t even say anything. When I got home I toke my wallet from my pocket and when I was putting my hand in my other pocket to take my iPhone from it, well, there was no iPhone. I really got desperate when I couldn’t find it. Maybe I already toke it from there and didn’t notice it? I checked all over the place and that was just not the case. So I opened my iCloud account and Find My iPhone was not able to locate anything. I said “DAMN!”. In a minute it found my iPhone. Shit, it must have got out of my pocket in the buss considering the place it was. So I ran to the bus stop and waited for the bus. After 2 buses, I found NOTHING! So I went to the civil police department and told them my phone was missing and that I was able to find it using Find My iPhone. They said they could not do anything and told me to call the military police. Brazil is one of the most expensive countries to live and the one who has the third highest taxes and what we get for that? NOTHING! So I got home and tried to locate it again and no luck. Waited a few more hours and no luck. The only thing I can think of is that someone found it and turned it off.

Today I had to get a new cellphone. I couldn’t afford another iPhone as they are very expensive here(in fact, Brazil has the world’s most expensive iPhone). My options were limited to 2 Android phones with 2 inch screens and a BlackBerry. I ended up getting the BB as it would be nearly impossible to type on those phones. Seriously guys, now I understand why Research In Motion is about to face a bankruptcy. This phone just sucks! I mean, those guys don’t really know what usability is. The keyboard is just to small. A touch screen phone is MUCH better.

I still have a very small hope of finding my iPhone. I will call the bus company on monday to see if they know anything. In case they don’t, I will just give it up and call every single Brazilian carrier and inform them the phone IMEI so no one will be able to active it on their networks. I just hope I will have money to buy another iPhone soon. 🙁

[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.

RIP Sensitive Code

No Comments

Hey folks, unfortunately, my blog Sensitive Code is dead. I had no time to update it and ended up not renewing the domain registration. It had a great page rank. For example, if you type UIFileSharing on Google, a post from Sensitive Code it is the first result(not sure for how long). I moved every post from there to this blog, so everything is still available. I hope to write about programming on this blog in the future.

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

Documents folder and UIFileSharing

No Comments

On the iOS, we can only save files on the documents folder. The bundle for example, is not writable. Getting the path of the documents folder is easy. Just use the following code:

NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documents = [[array objectAtIndex:0] copy];

The variable documents will be the path to the documents folder. Now if you want to create an URL from it, use the following code:

NSURL *url = [NSURL URLWithString:documents];

Say you saved a couple files and want your users to be able to transfer it to their computers. On iOS 3.2, Apple introduced UIFileSharing. It allows users to transfer files from their iOS devices to any computer running iTunes. To enable that, just add the Application supports iTunes file sharing line to your info.plist and check the box.

Your users will be able to transfer any file from the documents folder to a computer. To do that, open iTunes then click on your device name. Go to the apps tab and scroll down.

Just drag and drop any file to/from the documents table view.

FVImageSequence for Mac OS X/iOS

6 Comments

When I got to know Rainer Brockerhoff, one of my first questions was about networking. One of his advices was to write some open source code. A few days ago I was working on my customer’s app. He needed something similar to Apple’s 360° demo. I did not want to do that on a UIWebView as the performance is not the best. After looking for a view that does that, I found there was no one available. So I decided to write my own. Now I’m releasing it as an open-source project. The first of many.

FVImageSequence is basically a subclass of NSImageView/UIImageView that allows you to create the 360° effect by using a sequence of images. To use this view, you will have to add a image sequence to your project. All images must have the same prefix(i.e. myimage0.png, myimage1.png, myimage2.png). Set the prefix of the images you want to use by setting the prefix property.

You must also set the number of images. Just set the numberOfImages property in order to do that.

Also, don’t forget to set the property extension with the extension of the files(i.e png, jpg, gif).

Optionally you might set the increment property. This property basically tells the view how many images it should increment. If instead of incrementing 1 image, you want to increment 5, just set it to 5.

If you’re using the iOS version, don’t forget to enable the user interaction on Interface Builder.

Download the source code and the sample project from this link.

End of AT&T monopoly?

No Comments

First my friend who works at Verizon Wireless said it’s true. iPhone will be available to Verizon customers. I was surfing on CNN website and I found a video saying it’s probably gonna happen. I’m so happy to know that when I move to the US, I will not have to sign a contract with an carrier that sucks balls 🙂