Sunday, July 8, 2012

Write Debug Output to a File

NSLog definitely has its place in debugging. In a previous post I shared a version I wrote that skips displaying the date and object information, you can read more about the debug command I use on a regular basis here.
At some point, capturing debug statements to a file (versus the console) can be helpful to track down bugs. The good news is that you can continue to use NSLog (and/or the debug command from the previous post) by simply making a change to where stderr is directed.

Playing Sounds/Audio – Audio Session Services

If you need to play short sounds, less than 30 seconds, Audio Session Services are your friend. Here is a snippet of code to play a wav file:
SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle]
   pathForResource:@"RapidFire" ofType:@"wav"];    
 
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID);
AudioServicesPlaySystemSound (soundID);
For this to work, you will need to import <AudioToolbox/AudioToolbox.h> header file, and also add the AudioToolbox.framework to your project.

UIAlertView and Landscape Mode

I bumped into a rather odd UI issue early last week – I was working on an application which runs entirely in landscape mode. However, when I displayed an alert view, it came up as follows:

Changing Application Name on Home Screen

By default, the name of the application shown on the iPhone Home screen (below the icon) is the same as the project name. This will suffice in many cases, however, chances are the day will come when you’ll need to specify a different application name.
Changing the name is as simple as updating the Bundle Display Name in the info.plist file. By default this entry looks as follows:
Bundle Display Name: ${PRODUCT_NAME}
Simply replace the macro text with your preferred application name:
Bundle Display Name: Fubar
In my next post I’ll show you a trick to experiment with various names to see how they look on the Home screen, without having to go through the re-build, deploy cycle on your iPhone and/or the simulator.

Changing Views to Landscape Mode

As you well know, by default, iPhone applications launch in portrait mode. If you need to start your application in landscape mode, you can set UIInterfaceOrientation key in the plist file. The two possible values for this key are: UIInterfaceOrientationLandscapeLeft (iPhone home button will be on the left) and UIInterfaceOrientationLandscapeRight (home button on right).
For views to be shown in landscape mode, you must manually rotate the coordinate system 90 degrees. Here’s one way you can do that, let’s assume we have a class that is of typeUIViewController:

Play iPhone Movies in Portrait Mode with MPMoviePlayerController using Public API’s

Editor’s Note: With the release of SDK’s supporting 3.2 and 4.x, this approach is no longer necessary. The new movie player can now be displayed in either direction, landscape or portrait. Read this post for a more information: Display iPhone Movies in Portrait Mode (Updated)
It’s been covered by a number of websites and blogs on how to play movies in portrait mode using MPMoviePlayerController. Problem is, every solution that I’ve been able to find uses private API’s to tell the player to flip the direction of play.
Other than the built-in movie player, another option is to use a UIWebview, however, there are a few drawbacks including no support for notifications on when a movie has been preloaded, which is handy for displaying a “please wait” loading message.

Getting MPMoviePlayerController to Work with iOS4, 3.2 (iPad) and Earlier Versions of iPhone SDK

The API and overall approach for working with MPMoviePlayerController has changed just enough in the 3.2 SDK (iPad) and iOS4 SDK to cause working applications in earlier releases to be problematic when running on later SDKs. In this post I’ll walk through a short example of a movie player application that will work with 3.x, 3.2 and 4.0 SDKs.
In the next post, Display iPhone Movies in Portrait Mode, I’ll show how to create a movie player that runs in a view that is not fullscreen as well as how to show a few lines of code to display a movie in portrait mode – the one caveat here is that both of the tips in the second post will apply only to OS versions 3.2 and up.

Thursday, July 5, 2012

[J2ME] Send Text Message (Sms) using Wireless API

/* This example for sending sms using our SIM card.
Here im not using any PORT No to send the sms. so the received sms will be displayed in Inbox. This sms will be sent by using your sim card. so you will be charged for the same..*/

import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.wireless.messaging.*;
public class SendSms extends MIDlet implements CommandListener {
      Display display;
      private TextField toWhom;
      private TextField message;
      private Alert alert;
      private Command send,exit;
      MessageConnection clientConn;
      private Form compose;

Wednesday, July 4, 2012

PushRegistry, tự khởi động ứng dụng…

PushRegistry là gì??
PushRegistry chỉ có trong MIDlet 2.0
PushRegistry được dùng để cho phép ứng dụng tự động khởi động khi có một tác nhân bên ngoài tác động vào. Có 2 loại tác nhân ở đây là
1 Connection được thiết lập(Ví dụ: SMS tới chẳng hạn), loại thứ 2 là hẹn giờ, ví dụ hẹn đến 2h30 thì tự động khởi động chẳng hạn.
Ở đây tôi ví dụ với tác nhân thứ hai, tác nhân thứ nhất bạn có thể tự tìm hiểu. Đây không phải là một chuyên mục lớn nên tôi gợi ý,
các bạn có thể tự khám phá. Sau đây là Code của 1 MIDlet đơn giản ứng dụng PushRegistry.

J2ME - SMS

SMS là một trong những phát minh vĩ đại của con người, tính chất đó không những đúng trước kia mà bây giờ cũng vậy. SMS vẫn luôn là một tính năng rất tuyệt vời của điện thoại di động. Bạn không thể nói từ trước đến giờ bạn chưa bao giờ sử dụng SMS, chính điều đó đã chứng tỏ điều tôi muốn nói với các bạn. Hôm nay tôi xin giới thiệu sơ lược các thao tác cơ bản với SMS trên thiết bị di động.
Để có thể gửi và nhận SMS, bạn cần có một kết nối SMS(MessageConnection).
Có 2 loại: SMS server và SMS client. Dùng để gửi và nhận tin SMS.
Nói chung SMS server hoàn toàn có các tính năng của SMS client. Do đó ta nên dùng SMS server.
Khởi tạo SMS server:
MessageConnection msgCnn = (MessageConnection) Connector.open(“sms://123456:0001″);
=> Khởi tạo SMS server với số 12345 là tùy chọn và số này không quan trọng lắm, trường hợp cần thiết tôi sẽ nói sau. Và cổng của SMS server là 0001.
Cổng của MessageConnection là một điều hết sức quan trọng. Nếu gửi tin đi mà không có cổng thì thì tin nhắn đó sẽ giống như các tin nhắn bình thường và sẽ được trình nhận tin nhắn mặc định của điện thoại nhận và lưu trong hộp thư đến của máy. Trong trường hợp ta gửi có cổng(port) riêng thì tin nhắn đó sẽ được chương trình của ta tiếp nhận, tất nhiên là chương trình của ta phải có kết nối vào đúng cổng đó. Nếu không cũng chẳng có ai nhận SMS đó cả.

Popular Posts