Wednesday, February 23, 2011

iPad Launch screen image

With the usual requirement every iPad application is supposed to support all the orientations available, which a nice to have feature. In general the applications using a launch image for splash screen.

To supply an launch image, we use an image named as Default.png and is added to the resource folder of the application, and this image is loaded as launch image when the application is launched.
   
Since, we are using a single image for all orientations, there may be a case where the splash image me look stretched, blur, crisped (depending upon the image used).

This happens due to the different screen size of the device at different orientations. Landscape: 1024w x 748h  and Portrait: 768w x 1004h.
   
To get this thing to work we can create images with names and dimensions as mentioned below, and add them to the application resource folder (no code required).

Default-Portrait.png    768w x 1004h
Default-PortraitUpsideDown.png    768w x 1004h
Default-Landscape.png    1024w x 748h
Default-LandscapeLeft.png    1024w x 748h
Default-LandscapeRight.png    1024w x 748h
Default-PortraitUpsideDown.png    1024w x 748h


Clean the project by pressing Command+shift+k or from Build>Clean.
All set to go now, run the application.

NSSearchField return, arrow key press notification

In Cocoa development environment you might find NSSearchField difficult to trap the enter key event.
Also it becomes difficult to get the arrow key movements events.


In order to get these things to work, you need to do some simple stuffs with IBOutlet. You just need to connect your controller class with the delegate of NSSearchField.


In the controller class use below code to get the job done:

-(BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector {
    NSLog(@"doCommandBySelector");
    BOOL result = NO;
    if (commandSelector == @selector(insertNewline:)) {
        // enter key pressed
        result = YES;
    }
    else if(commandSelector == @selector(moveLeft:)) {
        // left arrow key pressed
        [textView moveLeft:nil];
        result = YES;
    }
    else if(commandSelector == @selector(moveRight:)) {
        // right arrow key pressed
        [textView moveRight:nil];
        result = YES;
    }
    else if(commandSelector == @selector(moveUp:)) {
        // up arrow key pressed
        result = YES;
    }
    else if(commandSelector == @selector(moveDown:)) {
        // down arrow key pressed
        result = YES;
    }
    return result;
}



Also, If you are interested in only in enter key event, set your controller class as the delegate of NSSearchField and implement the below method, which will be called when enter key is hit on the NSSearchField:
- (void)controlTextDidEndEditing:(NSNotification *)obj{
    NSLog(@"Enter key is hit");
}



* How to get the text out of NSSearchField:
The notification object(obj) in controlTextDidEndEditing method has the userInfo dictionary which contains the reference to the NSTextField in the NSSearchField control. Use below code to get the NSTextField object and the text in it.
NSTextView* textView = [[obj userInfo] objectForKey:@"NSFieldEditor"];
NSString *searchText=[textView string];





Let me know if something can be improved.

Monday, February 21, 2011

Foursquare

Where to register your application:
https://foursquare.com/oauth/

Sunday, February 20, 2011

Working with UILocalNotification in iOS

Back was the time before iPhone OS 3.0, APNS (apple push notification) was introduced. APN's are the means to send a remote notifications to a device connected to the internet.


With the increasing need of scheduling reminders at the device level, Local notification was introduced with the release iOS 4.0 . With the help of local notification, we can schedule a notification for any required date-time and the notification is handled by the device itself, no need to be connected to the
internet or a remote server.






UILocalNotification is the class behind the local notifications and the customization of the notification.


Local notification limitation:
Every application is allowed a maximum of 64 local notifications. iOS takes the upcoming 64 scheduled notifications and notifies for these notifications only, rest notifications are ignored.


1) How to registering Local notification:


    // Check for whether device supports local notification
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {
       
        UILocalNotification *notif = [[cls alloc] init];
        notif.fireDate = [datePicker date];
        notif.timeZone = [NSTimeZone defaultTimeZone];
       
        notif.alertBody = @"Whooaa?";
        notif.alertAction = @"Show";    // alert button title (other than cancel)
        notif.soundName = UILocalNotificationDefaultSoundName; (default alert sound name, can be cutomized)
        notif.applicationIconBadgeNumber = 1;
       
        // Associate a dictionary to identify to gather the information about the notification
        NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"Notification text"
                                                forKey:kRemindMeNotificationDataKey];
        notif.userInfo = userDict;
       
        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        [notif release];
    }



This will create a notification with the date selected in "datePicker" control.


In this case application name will be the title and "Whoaaa?" will be the body of the alert message, "Show" will be the title of the action button on alert (other than cancel button).


userInfo is the dictionary you will receive in the delegate method of the local notification. So, you can add your desired information for the notification to the dictionary while creating a notification.




2) How to handle notification delegate:


- This delegate method will be called If user tapped "Show Me" button and the application was running in background or was in active state.

- (void)application:(UIApplication *)application
        didReceiveLocalNotification:(UILocalNotification *)notification {
   
    application.applicationIconBadgeNumber = 0;
    NSString *reminderText = [notification.userInfo
                              objectForKey:kRemindMeNotificationDataKey];

    // Call to a method to handover the notification handling
    [viewController handleReminder:reminderText];
}





- This delegate method will be called If user tapped "Show Me" button and the application was not running in background.

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   

    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls) {
        UILocalNotification *notification = [launchOptions objectForKey:
                                UIApplicationLaunchOptionsLocalNotificationKey];
       
        if (notification) {
            NSString *reminderText = [notification.userInfo
                                      objectForKey:kRemindMeNotificationDataKey];

            // Call to a method to handover the notification handling
            [viewController handleReminder:reminderText];
        }
    }
   
    application.applicationIconBadgeNumber = 0;
   
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}




3) How to cancel all local notification:

You can cancel the selected local notification if you have preserved the notification object like,


 [[UIApplication sharedApplication] cancelLocalNotifications:notif];


where "notif" is the notification object(saved/unsaved) .


and you can cancel all the local notifications by calling below,
 [[UIApplication sharedApplication] cancelAllLocalNotifications];




4) Custom alert sound:
To make your local notification make a custom sound, you will have to provide the name of the sound file with extension as .caf . This sound file must be in your application resource bundle.
Below code registers a custom notification sound called "alert.caf".
notif.soundName = @"alert.caf";


Note: Alert sound must have .caf extension.


Wednesday, February 9, 2011

Emptying the trash using terminal

In Mac OSx, trashing a file takes it to the .Trash folder of the logged in user (unless we have used the option+delete command). If the trash folder is over whelmed with files in it, emptying the trash may not work, or delete all the files and folders in it.

In such case we have have the tool "Terminal" to empty the trash using unix command.

Mac OSx has unix in its kernel and thus gives the freedom to use the unix commands to perform our task.

How to delete the file in Trash:   
.Trash is the folder in every user account at location /Username/.Trash.
Open terminal from /Application/Utilities/ folder, enter the command "cd .Trash" in terminal and hit enter. Now you are in the .Trash directory.

Use -rm command to delete the file or folder.

If you want to empty the trash:                 $ rm -rf *.*
and If want to delete specific file:             rm -rf filename_with_extension


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

For more help about any unix COMMAND, use:
$whatis COMMAND
$man COMMAND (- Press RETURN for more, or q when done)
$info COMMAND


SOME MORE UNIX COMMANDS:
------------------------------------------------------------------------------
------------------------------------------------------------------------------
INTERACTIVE FEATURES
TAB                         Command completion !!! USEFUL !!!
UPARROW                     Command history !!! USEFUL !!!

CTRL-C                      Interrupt current process.
CTRL-D                      If a program/command waits for input, end input.
------------------------------------------------------------------------------
WILDCARDS AND DIRECTORIES USED IN COMMANDS
*                           Replaces any string of characters in a file name
                            except the initial dot.
?                           Replaces any single character in a file name
                            except the initial dot.
~                           The home directory of the current user.
~abcde123                   The home directory of the user abcde123.
..                          The parent directory.
.                           The present directory.
/                           The root directory

Example:
ls ~/csc219/*.txt
------------------------------------------------------------------------------
REDIRECTIONS AND PIPES

COMMAND < FILE              COMMAND will take input from FILE.
COMMAND > FILE              Put output of COMMAND to FILE
COMMAND >> FILE             Append the output of COMMAND to FILE
COMMAND 2> FILE             Put error messages of COMMAND to FILE.
COMMAND 2>> FILE            Append error messages of COMMAND to FILE.
COMMAND > FILE1 2> FILE2    Put output and error messages in separate files.
COMMAND >& FILE             Put output and error messages in the same FILE.
COMMAND >>& FILE            Append output and error messages of COMMAND to FILE.

COMMAND1 | COMMAND2         Output of COMMAND1 becomes input for COMMAND2.
COMMAND | more              See the output of COMMAND page by page.
COMMAND | sort | more       See the output lines of COMMAND sorted and page by page.
------------------------------------------------------------------------------
ONLINE HELP

h                           *Custom help.
COMMAND --help | more       Basic help on a Unix COMMAND (for most commands).
COMMAND -h | more           Basic help on a Unix COMMAND (for some commands).
whatis COMMAND              One-line information on COMMAND.
man COMMAND                 Display the UNIX manual page on COMMAND.
info COMMAND                Info help on COMMAND.
xman                        Browser for Unix manual pages (under X-windows).
apropos KEYWORD | more      Find man pages relevant to COMMAND.
help COMMAND            Help on a bash built-in COMMAND.
perldoc                     Perl documentation.
------------------------------------------------------------------------------
FILES AND DIRECTORIES

ls                          List contents of current directory.
ls -l                       List contents of current directory in a long form.
ls -a                       Same as ls but .* files are displayed as well.
ls -al                      Combination of ls -a and ls -l
ls DIRECTORY                List contents of DIRECTORY (specified by a path).
ls SUBDIRECTORY             List contents of SUBDIRECTORY.
ls FILE(S)                  Check whether FILE exists (or what FILES exist).

pwd                         Display absolute path to present working directory.

mkdir DIRECTORY             Create DIRECTORY (i.e. a folder)

cd                          Change to your home directory.
cd ..                       Change to the parent directory.
cd SUBDIRECTORY             Change to SUBDIRECTORY.
cd DIRECTORY                Change to DIRECTORY (specified by a path).
cd. ARGUMENTS               *Same as cd followed by ls

cp FILE NEWFILE             Copy FILE to NEWFILE.
cp -r DIR NEWDIR            Copy DIR and all its contents to NEWDIR.
cp. ARGUMENTS               *Same as cp -r but preserving file attributes.

mv FILE NAME                Rename FILE to new NAME.
mv DIR NAME                 Rename directory DIR to new NAME.
mv FILE DIR                 Move FILE into existing directory DIR.
ln -s FILE LINK             Create symbolic LINK (i.e. shortcut) to existing FILE.

quota                       Displays your disk quota.
quota.                      *Displays your disk quota and current disk usage.

rm FILE(S)                  Remove FILE(S).
rmdir DIRECTORY             Remove empty DIRECTORY.
rm -r DIRECTORY             Remove DIRECTORY and its entire contents.
rm -rf DIRECTORY            Same as rm -r but without asking for confirmations.
clean                       *Remove non-essential files, interactively
clean -f                    *Remove non-essential files, without interaction.
junk FILE                   *Move FILE to ~/junk instead of removing it.
find. FILE(S)               *Search current dir and its subdirs for FILE(S).
touch FILE                  Update modification date/time of FILE.
file FILE                   Find out the type of FILE.
gzip                        Compress or expand files.
zip                         Compress or expand files.
compress                    Compress or expand files.
tar                         Archive a directory into a file, or expand such a file.
targz DIRECTORY             *Pack DIRECTORY into archive file *.tgz
untargz ARCHIVE.tgz         *Unpack *.tgz archive into a directory.

------------------------------------------------------------------------------
TEXT FILES

more FILE                   Display contents of FILE, page by page.
less FILE                   Display contents of FILE, page by page.
cat FILE                    Display a file. (For very short files.)
head FILE                   Display first lines of FILE.
tail FILE                   Display last lines of FILE.

pico FILE                   Edit FILE using a user-friendly editor.
nano FILE                   Edit FILE using a user-friendly editor.
kwrite FILE                 Edit FILE using a user-friendly editor under X windows.
gedit FILE                  Edit FILE using a user-friendly editor under X windows.
emacs FILE                  Edit FILE using a powerful editor.
vim FILE                    Edit FILE using a powerful editor with cryptic syntax.
aspell -c FILE              Check spelling in text-file FILE.
ispell FILE                 *Check spelling in text-file FILE.

cat FILE1 FILE2 > NEW       Append FILE1 and FILE2 creating new file NEW.
cat FILE1 >> FILE2          Append FILE1 at the end of FILE2.

sort FILE > NEWFILE         Sort lines of FILE alphabetically and put them in NEWFILE.

grep STRING FILE(S)         Display lines of FILE(S) which contain STRING.
grep. STRING FILE(S)        *Similar as above, but better.
wc FILE(S)                  Count characters, words and lines in FILE(S).
diff FILE1 FILE2 | more     Show differences between two versions of a file.

filter FILE NEWFILE         *Filter out strange characters from FILE.
COMMAND | cut -b 1-9,15     Remove sections from each line.
COMMAND | uniq              Omit repeated lines.
------------------------------------------------------------------------------
PRINTING

lpr FILE                    In Hawk153B, print FILE from a workstation.
lprint1 FILE                *Print text-file on local printer; see help printing
lprint2 FILE                *Print text-file on local printer; see help printing

------------------------------------------------------------------------------
PROGRAMMING LANGUAGES

javac CLASSNAME.java        Compile a Java program.
java CLASSNAME              Run a Java program.
javadoc CLASSNAME.java      Create an html documentation file for CLASSNAME.
appletviewer CLASSNAME      Run an applet.

lisp                        *Listener of LISP programming language.

prolog                      *Listener of Prolog programming language.
python                      Listener of Python programming language.
cc -g -Wall -o FILE FILE.c  Compile C source FILE.c into executable FILE.
gcc -g -Wall -o FILE FILE.c Compile C source FILE.c into executable FILE.
c++ -g -Wall -o FIL FIL.cxx Compile C++ source FIL.cxx into executable FIL.
g++ -g -Wall -o FIL FIL.cxx Compile C++ source FIL.cxx into executable FIL.
gdb EXECUTABLE              Start debugging a C/C++ program.
make FILE                   Compile and link C/C++ files specified in makefile
m                           *Same as make but directs messages to a log file.
c-work                      *Repeatedly edit-compile-run a C program.
------------------------------------------------------------------------------
INTERNET
lynx                        Web browser (for text-based terminals).
firefox                     Web browser.
konqueror                   Web browser.
BROWSER                     Browse the Internet.
BROWSER FILE.html           Display a local html file.
BROWSER FILE.pdf            Display a local pdf file.

mutt                        Text-based e-mail manager.
pine                        Text-based e-mail manager (on some systems).

ssh HOST                    Open interactive session on HOST using secure shell.
sftp HOST                   Open sftp (secure file transfer) connection to HOST.
rsync ARGUMENTS             Synchronize directories on local and remote host.
------------------------------------------------------------------------------
PROCESS CONTROL
Notes: A process is a run of a program;
       One program can be used to create many concurrent processes.
       A job may consist of several processes with pipes and redirections.
       Processes are managed by the kernel.
       Jobs are managed by a shell.
   
CTRL-Z                      Suspend current foreground process.
fg                          Bring job suspended by CTRL-Z to the foreground.
bg JOB                      Restart suspended JOb in the background.
ps                          List processes.
ps.                         *List processes.
jobs                        List current jobs (A job may involve many processes).
kill PROCESS                Kill PROCESS (however some processes may resist).
ctrl-C                      Kill the foreground process (but it may resist).
kill -9 PROCESS             Kill PROCESS (no process can resist.)
kill. PROCESS               *Kill PROCESS; same as kill -9.
COMMAND &                   Run COMMAND in the background.
------------------------------------------------------------------------------
ENVIRONMENT VARIABLES IN BASH
env | sort | more           List all the environment variables with values.
echo $VARIABLE              List the value of VARIABLE.
unset VARIABLE              Remove VARIABLE.
export VARIABLE=VALUE       Create environment variable VARIABLE and set to VALUE.
------------------------------------------------------------------------------
MISCELLANEOUS

exit                        Exit from any shell.
logout                      Exit from the login shell and terminate session.

svn                         Version control system.

xterm                       A shell window under X-windows.
xcalc                       A calculator under X-windows.
xclock                      A clock under X windows.
xeyes                       They watch you work and report to the Boss :-)

date                        Display date and time.

clear                       Clear shell window.
xrefresh                    Refresh X-windows.
reset                       *Reset session.
setup-account               *Set up or reset your account (Mr. Dela's customizations)
------------------------------------------------------------------------------
COURSEWORK IN DR. PLAZA'S COURSES
Commands and directory names related to csc219 have 219 as a suffix.
By changing the suffix you will obtain commands for other courses.
ls $csc219                  *List files related to csc219.
cd $csc219                  *change into instructor's public directory for csc219.
cp $csc219/FILE .           *Copy FILE related to csc219 to the current directory
cp -r $csc219/SUBDIR .      *Copy SUBDIR of csc219 to the current directory.
submit                      *Submit a directory with files for an assignment.
grades                      *See your grades. Used in some courses only.
------------------------------------------------------------------------------

Monday, February 7, 2011

Weak link in iOS framework


Well, there happened a case when I was using the latest iOS SDK  for the development purpose, and built an application which utilized the eventKit framework, and the framework used "eventKit" was a new addition to the framework list.

I used the eventKit on the fly and submitted to the appstore for the approval process, and as a matter the application was approved.

But, the case happened when the application was being downloaded and it used to crash at the app launch on the earlier iOS's.

Digging around the problem, I came to know about the weak link thing for a framework, and uploaded the updated build to app store.

The idea is that, If you are using a framework that is not available to all the devices that you have selected as target devices, make the framework as weak link.

This can be done as below:
* Select the project target > Right click > Get-Info.
* Go to general tab > Linked libraries.
* Select the framework and make it a weak link.
Right click on the target ans select info.


Select weak link from type column.

Also, keep in if you mark a framework as weak linked, be sure to check for its availability before using any of its functionally.

You can check for the existence of the class like below code sample:

Class theClass = (NSClassFromString(@"UILocalNotification"));
if(theClass){
// Class exists
}
else{
// Class does not exists
}

Thursday, February 3, 2011

Symbolicate crash logs

Symbolicating of crash logs is the process of converting the HEX addresses into readable symbols (class/method names).
It is helpful to resolve the crashing issues of your application.
The crash logs for live appStore application can be retrieved from iTuneConnect web portal.
And during testing of your application the crash logs are retrieved from device by syncing the device with itune application. After sync. crash logs are stored in system at "~/Library/Logs/CrashReporter/MobileDevice/" for Mac OSx and at "C:\Users\\AppData\Roaming\Apple computer\Logs\CrashReporter/MobileDevice/" for Windows7 PC.

The crash log may seem as below:













Digging about reading the crash logs, here are the steps to get the class/method names in the .crash file.

1. Sync the device with your system.

2. Create a folder on the desktop, say "crashFiles",just to keep all files at one place.

3. Paste AppName.app.dSYM files to "crashFile" folder.
(Note: This file is created through xCode in your release folder)

4. Copy the .symbolicatecrash file in your system from the location "/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKit.framework/Versions/A/Resources/" & paste the file to "carshFile" folder on desktop.

5. Locate the .Crash file in your system. Following are the paths for .Crash file in different OS.
- Mac OS X : ~/Library/Logs/CrashReporter/MobileDevice/
- Windows XP: C:\Documents and Settings\
\Application Data\Apple computer\Logs\CrashReporter/
- Windows Vista: C:\Users\
\AppData\Roaming\Apple computer\Logs\CrashReporter/MobileDevice/
- Paste the .crash file in "crashFile" on desktop.
6. Start "terminal" from spotlight or Utilities folder in Applictions folder.
7. Run the below command with absolute path to all files:
 - $ symbolicatecrash AppName.crash AppName.app.dSYM > report-with-symbols.crash

OR
 - Drag and Drop symbolicatecrash file on terminal.

 - Drag and Drop .crash file on terminal.

 - Drag and Drop .app.dSYM file on terminal.
8. Now type ">report-with-symbols.crash" and hit enter.

Running above command will create a .Crash file "report-with-symbols.crash" replacing the symbols with more descriptive class/function name to dig in. The generate file may seem like below:






Happy coding...