Showing posts with label Developers. Show all posts
Showing posts with label Developers. Show all posts

Jul 7, 2010

Understanding iOS 4 Backgrounding and Delegate Messaging

The World Before Multitasking

The first thing that I learned from this is that applicationDidBecomeActive: is being called right after application:didFinishLaunchingWithOptions:. So even before 4.0 it would have been smart to put there any kind of code that you want executed whenever the app becomes active, be it after app start or upon rejecting a phone call.

Not shown on this diagram is the situation that your app is eating up all the system memory and ignores both the level 1 and level 2 memory warnings. In that case the OS will also terminate your app without totally unscrupulous.

The mechanism with WillResignActive and DidBecomeActive is sort of the Backgrounding Lite that has always been there. This occurs whenever some other thing is displayed in front of your app. This could be the UI to accept a phone call or something as benign as the synching screen.

Multitasking ON

Adding multitasking to this flow chart makes it about twice as complex. I probably spent an hour trying to fit it all together with no crossing lines. Another thing that I noticed while doing this is that applicationWillResignActive: is the only delegate method that I could not optimize into a single box, because one use is to show that the app has been interrupted, the other is to the path into the background.


An app built with 3.2 will still go through a short background stage where applicationDidEnterBackground: is called. but then it will be terminated as usual. If the same app is built against a 4.x SDK then it will not go straight from background to being terminated. Instead it will stick around and so will be the debugger. As soon as you tap the app icon again or choose it from the app switcher it is first informed that applicationWillEnterForeground and then applicationDidBecomeActive.

An app that is suspended but still in RAM might be terminated by the OS if memory runs low. But after entering the background there is no longer any delegate method being called, instead the app will receive a KILL signal. This occurs also if the user long-presses the app icon in app switcher and then removes the app from there with the removal button.

Accepting a phone call no longer terminates your app but will send it into the appropriate background mode. Within the background box you see two purple states that the app can be in. All apps are suspended in RAM per default. You might want to slim down your memory footprint to make your app a less likely target for killing if the system runs low on memory.

Only apps that actually require background processing continue to be executing. This requirement is either set in info.plist or by telling the OS that you have a task to complete, like for example a file upload.

The following kinds of activities get to run in true multi tasking behind the foreground app with lesser CPU priority.

  • playing music: “App plays audio”
  • geo location: “App registers for location updates”
  • VOIP: “App provides Voice over IP services”

If your app does one of these things then adding the key to info.plist is all it takes. But be aware that as soon as your app stops doing what it stated it would be doing the OS again will send it to sleep, only to be awakend by another gentle tap by the user.

In background mode you’re advised to stop updating the UI. Especially with OpenGL Apple is really strict. If you app as much as touches OpenGL while in background the app gets killed right away.

There are only two scenarios left where your app’s applicationWillTerminate: will actually be called: if it’s build with an SDK of less than version 4.0 or if you chose to opt out of backgrounding by adding the UIApplicationExitsOnSuspend key to your info.plist.

So, let’s ask the question we’ve been doing all this fuss for: Where should you now put your code to initialize, update or save changes? applicationWillTerminate not being called in the majority of cases makes it a rather bad candidate to save user defaults or data.

Looking at the chart I see applicationDidEnterBackground as the ideal candidate delegate method for saving state. This is also the last method to be called before a regular 4.0 app gets put to sleep and before a possible kill.

For updating data from the web the case is not as clear. You would not want to reload every time the user comes back to your app. Possible applicationDidBecomeActive: is a good place, provided that you only reload data if sufficient time has passed to be able to assume that something new is available.

Only the first loading of data can stay in application:didFinishLaunchingWithOptions: since every call applicationDidBecomeActive: most likely has the data already loaded previously.

Conclusion

Adding fast app switching and multitasking support is quite easy since for the most part you don’t need to do anything. But you WILL have to review the contents of your app delegate methods to see which code has to be moved into one of the other delegate methods now. Clean out applicationWillTerminate: and have a close look at application:didFinishLaunchingWithOptions: to check if you have something in there that needs to be done every time the app becomes active.

These charts come from some experimentation that I did and what I remembered from the WWDC 2010 session videos on multitasking. Potentially there are mistakes or more surprises hidden in there. Please let me know if you find any.

Here’s the chart in PDF format in case you want to print it out and frame it.

source

May 7, 2010

WWDC 2010 is Sold Out Already


Apple is indicating that tickets for WWDC 2010 are sold out just eight days after being announced.

The Worldwide Developers Conference (WWDC) takes place June 7 through June 11 at San Francisco’s Moscone West. The five-day conference includes the first ever iPad development sessions and hands-on working labs for iPhone OS 4, as well as Mac OS X core technology labs.

Apple is widely expected to annnounce the new fourth generation iPhone at the event.

iclarified.com

Apr 29, 2010

An A-Z Index of the Apple OS X Command Line

a
 alias     Create an alias •
alloc List used and free memory
apropos Search the whatis database for strings
awk Find and Replace text within file(s)
b
basename Convert a full pathname to just a filename
bash Bourne-Again SHell
bg Send to background •
bind Display readline key and function bindings •
bless Set volume bootability and startup disk options.
break Exit from a For, While, Until or Select loop •
builtin Execute a shell builtin •
bzip Compress or decompress files
c
cal Display a calendar
caller Return the context of a subroutine call •
case Conditionally perform a command •
cat Display the contents of a file
cd Change Directory •
chflags Change a file or folder's flags
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
chroot Run a command with a different root directory
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
command Run a command (not a function) •
complete Edit a command completion [word/pattern/list] •
continue Resume the next iteration of a loop •
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later date/time
cut Divide a file into several parts
d
date Display or change the date & time
dc Desk Calculator
dd Data Dump - Convert and copy a file
declare Declare variable & set attributes •
defaults Set preferences, show hidden files
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dig DNS lookup
dirname Convert a full pathname to just a path
dirs Display list of remembered directories •
diskutil Disk utilities - Format, Verify, Repair
disown Unbind a job from the current login session •
ditto Copy files and folders
dot_clean Remove dot-underscore files
drutil Interact with CD/DVD burners
dscacheutil Query or flush the Directory Service/DNS cache
dscl Directory Service command line utility
du Estimate file space usage
e
echo Display message on screen •
ed A line-oriented text editor (edlin)
enable Enable and disable builtin shell commands •
env Set environment and run a utility
eval Evaluate several commands/arguments •
exec Execute a command •
exit Exit the shell •
expand Convert tabs to spaces
expect Programmed dialogue with interactive programs
Also see AppleScript
export Set an environment variable •
expr Evaluate expressions
f
false Do nothing, unsuccessfully
fc Fix command (history)
fdisk Partition table manipulator for Darwin UFS/HFS/DOS
fg Send job to foreground •
file Determine file type
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width
for Loop command •
fsck Filesystem consistency check and repair
fsaclctl Filesystem enable/disable ACL support
fs_usage Filesystem usage (process/pathname)
ftp Internet file transfer program
g
GetFileInfo Get attributes of HFS+ files
getopt Parse positional parameters
getopts Parse positional parameters •
goto Jump to label and continue execution
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress files
h
hash Refresh the cached/remembered location of commands •
head Display the first lines of a file
hdiutil Manipulate iso disk images
history Command History •
hostname Print or set system name
i
id Print user and group names/id's
if Conditionally perform a command •
info Help info
install Copy files and set attributes
j
jobs List active jobs •
join Join lines on a common field
k
kextfind List kernel extensions
kickstart Configure Apple Remote Desktop
kill Stop a process from running
l
l List files in long format (ls -l)
last Indicate last logins of users and ttys
launchctl Load or unload daemons/agents
ll List files in long format, showing invisible files (ls -la)
less Display output one screen at a time
let Evaluate expression •
lipo Convert a universal binary
ln Make links between files (hard links, symbolic links)
local Set a local (function) variable •
locate Find files
logname Print current login name
login log into the computer
logout Exit a login shell (bye) •
lpr Print files
lprm Remove jobs from the print queue
lpstat Printer status information
ls List information about file(s)
lsregister Reset the Launch Services database
lsbom List a bill of materials file
lsof List open files
m
man Help manual
mdfind Spotlight search
mdutil Manage Spotlight metadata store
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
more Display output one screen at a time
mount Mount a file system
mv Move or rename files or directories
n
net Manage network resources
netstat Show network status
networksetup Network and System Preferences
nice Set the priority of a command
nohup Run a command immune to hangups
ntfs.util NTFS file system utility
o
onintr Control the action of a shell interrupt
open Open a file/folder/URL/Application
osacompile Compile Applescript
osascript Execute AppleScript
p
passwd Modify a user password
paste Merge lines of files
pbcopy Copy data to the clipboard
pbpaste Paste data from the Clipboard
pico Simple text editor
ping Test a network connection
pkgutil Query and manipulate installed packages
plutil Property list utility
pmset Power Management settings
popd Restore the previous value of the current directory •
pr Convert text files for printing
printenv Print environment variables
printf Format and print data •
ps Process status
pushd Save and then change the current directory
pwd Print Working Directory •
q
quota Display disk usage and limits
r
rcp Copy files between machines
read Read one line from standard input •
readonly Mark a variable or function as read-only •
reboot Stop and restart the system
return Exit a function •
rev Reverse lines of a file
rm Remove files
rmdir Remove folder(s)
rpm Remote Package Manager
rsync Remote file copy - Sync file tree (also RsyncX)
s
say Convert text to audible speech
screen Multiplex terminal, run remote shells via ssh
screencapture Capture screen image to file or disk
sdiff Merge two files interactively
security Administer Keychains, keys, certificates and the Security framework
sed Stream Editor
select Generate a list of items •
set Set a shell variable = value •
setfile Set attributes of HFS+ files
shift Shift positional parameters •
shopt Set shell options •
shutdown Shutdown or restart OS X
sleep Delay for a specified time
softwareupdate System software update tool
sort Sort text files
source Execute commands from a file •
split Split a file into fixed-size pieces
stop Stop a job or process
su Substitute user identity
sudo Execute a command as another user
sum Print a checksum for a file
suspend Suspend execution of this shell •
sw_vers Print Mac OS X operating system version
system_profiler Report system configuration
systemsetup Computer and display system settings
t
tail Output the last part of files
tar Tape ARchiver
tee Redirect output to multiple files
test Condition evaluation •
textutil Manipulate text files in various formats (Doc,html,rtf)
time Measure Program Resource Use
times Print shell & shell process times •
touch Change file timestamps
tr Translate, squeeze, and/or delete characters
trap Execute a command when the shell receives a signal •
traceroute Trace Route to Host
true Do nothing, successfully
tty Print filename of terminal on stdin
type Describe a command •
u
ufs.util Mount/unmount UFS file system
ulimit limit the use of system-wide resources •
umask Users file creation mask
umount Unmount a device
unalias Remove an alias •
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unset Remove variable or function names •
until Loop command •
users Print login names of users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
uuidgen Generate a Unique ID (UUID/GUID)
uucp Unix to Unix copy
v
vi Text Editor
w
wait Wait for a process to complete •
wc Print byte, word, and line counts
whatis Search the whatis database for complete words
where Report all known instances of a command
which Locate a program file in the user's path
while Loop command •
who Print all usernames currently logged on
whoami Print the current user id and name (`id -un')
write Send a message to another user
x
xargs Execute utility - passing arguments
yes Print a string until interrupted
Commands marked • are bash built-in commands.
OS X Panther 10.3, Tiger 10.4 and Leopard 10.5 default to running the bash shell, this runs under 'Darwin' the open source core of OSX

ss64.com/osx/

Apr 28, 2010

Apple Worldwide Developers Conference Kicks Off June 7 in San Francisco


The “center of the app universe” will be at Moscone West in San Francisco this year, as WWDC10 kicks off on June 7 and runs through the 11th.

In a press release, Senior Apple VP Scott Forstall doesn’t even pretend it’s about the Mac anymore. WWDC will provide “in-depth sessions and hands-on working labs to learn more about iPhone OS 4,” helping developers “make their iPhone and iPad apps even better.”

And it doesn’t end there, unless we’re talking about information on the next iteration of Mac OS X.

For developers, the $1,599 package gets you in on five technology tracks: Application Frameworks; Internet & Web; Graphics & Media; Developer Tools; and Core OS, but no IT/SysAdmin track. The sessions offer blanket coverage of iPhone OS development, but unless OS X 10.7 sessions will be super secret, there doesn’t appear to be a lot there. It sure seems telling that five design awards will be handed out for the iPhone and the iPad, but not the Mac.

For those who are not developers, expect to see the next generation iPhone, rumored to be named the iPhone HD. If the infamous prototype revealed by Gizmodo is the final version, its hardware features will include: a front-facing video camera, camera flash, micro-SIM card, and two volume buttons. Also, John Gruber has suggested the resolution of the display will jump to 960×640. The launch date for the phone will certainly be announced, probably June or early July.

That phone will be running iPhone OS 4, of course, which has already been previewed. There may be a few new features, along with information about a “unity release” of iPhone OS 4.1 for the iPhone, iPod touch, and iPad sometime in late summer or early fall.

theappleblog.com

Apr 5, 2010

My first iPhone web app



This is the first time I learn making web app for iphone. So check it out yo! You can find the tutorial on theappleblog.com. I use iwebkit. This is the screenshots from my mac.



This is the copy of my code if you want to take a look at it. Use dashcode to edit it.