Apple Event Handling Guide for iOS Manuel
Apple sur Fnac.com
- Pour voir la liste complète des manuels APPLE, cliquez ici
-->
ou juste avant la balise de fermeture -->
TELECHARGER LE PDF sur :
Commander un produit Apple sur Fnac.com
Voir également d'autres Guides et documentation APPLE :
Apple-InstrumentsUserGuide.pdf-manuel
Apple-Logic-Pro-9-TDM-Guide-manuel
Apple-macbook_air_users_guide.pdf-manuel
Apple-macbook_air-13-inch_mid-2012-qs_ta.pdf-manuel
Apple-AppStoreMarketingGuidelines-JP.pdf-Japon-manuel
Apple-macbook_pro_retina_qs_ta.pdf-manuel
Apple-ipad_user_guide_tu.pdf-manuel
Apple-ipad_user_guide_th.pdf-manuel
Apple-iphone_user_guide_gr.pdf-manuel
Apple-Nike_Plus_iPod_Sensor_UG_2A.pdf-manuel
Apple-ipad_manual_del_usuario.pdf-manuel
Apple-ipad_uzivatelska_prirucka.pdf-manuel
Apple-ipad_wifi_informations_importantes.pdf-manuel
Apple-Xsan_2_Admin_Guide_v2.3.pdf-manuel
Apple-macbook_pro-13-inch-late-2012-quick_start.pdf-manuel
Apple-CocoaDrawingGuide.pdf-manuel
Apple-Cryptographic-Services-Guide-manuel
Apple-Resource-Programming-Guide-manuel
AppleSafariVisualEffectsProgGuide.pdf-manuel
/Apple-WorkingWithUSB.pdf-manuel
Apple-macbook_pro-retina-mid-2012-important_product_info_f.pdf-manuel
Apple-iOS_Security_May12.pdf-manue
Apple-Mac-Pro-2008-Performance-and-Productivity-for-Creative-Pros
Apple-iPod_shuffle_4thgen_Manuale_utente.pdf-Italie-Manuel
Apple-KernelProgramming.pdf-manuel
Apple-Core-Data-Model-Versioning-and-Data-Migration-Programming-Guide-manuel
Apple-RED_Workflows_with_Final_Cut_Pro_X.pdf-manuel
Apple-Transitioning-to-ARC-Release-Notes-manuel
Apple-iTunes-Connect-Sales-and-Trends-Guide-manuel
Apple-App-Sandbox-Design-Guide-manuel
Apple-String-Programming-Guide-manuel
Apple-Secure-Coding-Guide-manuel
Apple_AirPort_Networks_Early2009.pdf-manuel
Apple-TimeCapsule_SetupGuide_TA.pdf-manuel
Apple-time_capsule_4th_gen_setup.pdf-manuel
Apple-TimeCapsule_SetupGuide.pdf-manuel
Apple-TimeCapsule_SetupGuide_CH.pdf-Chinois-manuel
Apple-CodeSigningGuide.pdf-manuel
Apple-ViewControllerPGforiOS.pdf-manuel
Apple-KeyValueObserving.pdf-manuel
Apple-mac_mini-late-2012-quick_start.pdf-manuel
Apple-OS-X-Mountain-Lion-Core-Technologies-Overview-June-2012-manuel
Apple-OS-X-Server-Product-Overview-June-2012-manuel
Apple-Apple_Server_Diagnostics_UG_109.pdf-manuel
Apple-PackageMaker_UserGuide.pdf-manuel
Apple-Instrumentos_y_efectos_de_Logic_Studio.pdf-Manuel
Apple-ipod_nano_kayttoopas.pdf-Finlande-Manuel
Apple_ProRes_White_Paper_October_2012.pdf-Manuel
Apple-wp_osx_configuration_profiles.pdf-Manuel
Apple-UsingiTunesProducerFreeBooks.pdf-Manuel
Apple-ipad_manual_do_usuario.pdf-Portugais-Manuel
Apple-Instruments_et_effets_Logic_Studio.pdf-Manuel
Apple-ipod_touch_gebruikershandleiding.pdf-Neerlandais-Manuel
AppleiPod_shuffle_4thgen_Manual_del_usuario.pdf-Espagnol-Manuel
Apple-Premiers-contacts-avec-votre-PowerBook-G4-Manuel
Apple_Composite_AV_Cable.pdf-Manuel
Apple-iPod_shuffle_3rdGen_UG_DK.pdf-Danemark-Manuel
Apple-iPod_classic_160GB_Benutzerhandbuch.pdf-Allemand-Manuel
Apple-VoiceOver_GettingStarted-Manuel
Apple-iPod_touch_2.2_Benutzerhandbuch.pdf-Allemand-Manuel
Apple-Apple_TV_Opstillingsvejledning.pdf-Allemand-Manuel
Apple-iPod_shuffle_4thgen_Manuale_utente.pdf-Italie-Manuel
Apple-iphone_prirucka_uzivatela.pdf-Manuel
Apple-Aan-de-slag-Neerlandais-Manuel
Apple-airmac_express-80211n-2nd-gen_setup_guide.pdf-Thailande-Manuel
Apple-ipod_nano_benutzerhandbuch.pdf-Allemand-Manuel
Apple-aperture3.4_101.pdf-Manuel
Apple-Pages09_Anvandarhandbok.pdf-Manuel
Apple-nike_plus_ipod_sensor_ug_la.pdf-Mexique-Manuel
Apple-ResEdit-Reference-For-ResEdit02.1-Manuel
Apple-ipad_guide_de_l_utilisateur.pdf-Manuel
Apple-Compressor-4-Benutzerhandbuch-Allemand-Manuel
Apple-AirPort_Networks_Early2009_DK.pdf-Danemark-Manuel
Apple-MacBook_Pro_Mid2007_2.4_2.2GHz_F.pdf-Manuel
Apple-MacBook_13inch_Mid2010_UG_F.pdf-Manuel
Apple-Xserve-RAID-Presentation-technologique-Janvier-2004-Manuel
Apple-MacBook_Pro_15inch_Mid2010_F.pdf-Manuel
Apple-AirPort_Express-opstillingsvejledning.pdf-Danemark-Manuel
Apple-DEiPod_photo_Benutzerhandbuch_DE0190269.pdf-Allemand-Manuel
Apple-Final-Cut-Pro-X-Logic-Effects-Reference-Manuel
Apple-iPod_touch_2.1_Brugerhandbog.pdf-Danemark-Manuel
Apple-Remote-Desktop-Administratorhandbuch-Version-3.1-Allemand-Manuel
Apple-Qmaster-4-User-Manual-Manuel
Apple-Server_Administration_v10.5.pdf-Manuel
Apple-ipod_classic_features_guide.pdf-Manuel
Apple-iPhone_Finger_Tips_Guide.pdf-Anglais-Manuel
Apple-Boitier-de-l-ordinateur-Manuel
Apple-Guide_de_configuration_de_l_Airport_Express_5.1.pdf-Manuel
Apple-iMac_Mid2010_UG_F.pdf-Manuel
Apple-MacBook_13inch_Mid2009_F.pdf-Manuel
Apple-MacBook_Mid2007_UserGuide.F.pdf-Manuel
Apple-Designing_AirPort_Networks_10.5-Windows_F.pdf-Manuel
Apple-Administration_de_QuickTime_Streaming_et_Broadcasting_10.5.pdf-Manuel
Apple-Opstillingsvejledning_til_TimeCapsule.pdf-Danemark-Manuel
Apple-iPod_nano_5th_gen_Benutzerhandbuch.pdf-Manuel
Apple-AirPort_Extreme_Installationshandbuch.pdf-Manuel
Apple-Final_Cut_Express_4_Installation_de_votre_logiciel.pdf-Manuel
Apple-MacBook_Pro_15inch_2.53GHz_Mid2009.pdf-Manuel
Apple-Network_Services.pdf-Manuel
Apple-Aperture_Performing_Adjustments_f.pdf-Manuel
Apple-Supplement_au_guide_Premiers_contacts.pdf-Manuel
Apple-Administration_des_images_systeme_et_de_la_mise_a_jour_de_logiciels_10.5.pdf-Manuel
Apple-Mac_OSX_Server_v10.6_Premiers_contacts.pdf-Francais-Manuel
Apple-Designing_AirPort_Networks_10.5-Windows_F.pdf-Manuel
Apple-Mise_a_niveau_et_migration_v10.5.pdf-Manue
Apple-MacBookPro_Late_2007_2.4_2.2GHz_F.pdf-Manuel
Apple-Mac_mini_Late2009_SL_Server_F.pdf-Manuel
Apple-Mac_OS_X_Server_10.5_Premiers_contacts.pdf-Manuel
Apple-iPod_touch_2.0_Guide_de_l_utilisateur_CA.pdf-Manuel
Apple-MacBook_Pro_17inch_Mid2010_F.pdf-Manuel
Apple-Comment_demarrer_Leopard.pdf-Manuel
Apple-iPod_2ndGen_USB_Power_Adapter-FR.pdf-Manuel
Apple-Feuille_de_operations_10.4.pdf-Manuel
Apple-Time_Capsule_Installationshandbuch.pdf-Allemand-Manuel
Apple-F034-2262AXerve-grappe.pdf-Manuel
Apple-Mac_Pro_Early2009_4707_UG_F
Apple-imacg5_17inch_Power_Supply
Apple-Logic_Studio_Installieren_Ihrer_Software_Retail
Apple-Aperture_Getting_Started_d.pdf-Allemand
Apple-getting_started_with_passbook
Apple-iPod_mini_2nd_Gen_UserGuide.pdf-Anglais
Apple-Deploiement-d-iPhone-et-d-iPad-Reseaux-prives-virtuels
Apple-Mac_OS_X_Server_Glossaire_10.5
Apple-iphone_bluetooth_headset_userguide
Apple-Administration_des_services_reseau_10.5
Apple-iPod_nano_4th_gen_Manuale_utente
Apple-iBook-G4-Getting-Started
Apple-Guide_des_fonctionnalites_de_l_iPod_classic
Apple-Guide_de_configuration_d_Xsan_2
Apple-MacBook_Late2006_UsersGuide
Apple-Mac_mini_Mid2010_User_Guide_F.pdf-Francais
Apple-PowerBookG3UserManual.PDF.Anglais
Apple-Installation_de_votre_logiciel_Logic_Studio_Retail
Apple-Pages-Guide-de-l-utilisateur
Apple-MacBook_Pro_13inch_Mid2009.pdf.Anglais
Apple-MacBook_Pro_15inch_Mid2009
Apple-Installation_de_votre_logiciel_Logic_Studio_Upgrade
Apple-airportextreme_802.11n_userguide
Apple-iPod_classic_160GB_User_Guide
Apple-iPod_nano_5th_gen_UserGuide
Apple-ipod_touch_features_guide
Apple-Wireless_Mighty_Mouse_UG
Apple-Advanced-Memory-Management-Programming-Guide
Apple-iOS-App-Programming-Guide
Apple-Concurrency-Programming-Guide
Apple-MainStage-2-User-Manual-Anglais
Apple-iMacG3_2002MultilingualUserGuide
Apple-iBookG3_DualUSBUserGuideMultilingual.PDF.Anglais
Apple-Guide_de_l_utilisateur_de_Mac_Pro_Early_2008
Apple-Installation_de_votre_logiciel_Logic_Express_8
Apple-iMac_Guide_de_l_utilisateur_Mid2007
Apple-imacg5_20inch_OpticalDrive
Apple-FCP6_Formats_de_diffusion_et_formats_HD
Apple-prise_en_charge_des_surfaces_de_controle_logic_pro_8
Apple-Aperture_Quick_Reference_f
Apple-aluminumAppleKeyboard_wireless2007_UserGuide
Apple-ipod_shuffle_features_guide
ApplePowerMacG5_(Early_2005)_UserGuide
Apple-MacBook_Pro_Early_2008_Guide_de_l_utilisateur
Apple-Nouvelles-fonctionnalites-aperture-1.5
Apple-premiers_contacts_2e_ed_10.4.pdf-Mac-OS-X-Server
Apple-premiers_contacts_2e_ed_10.4
Apple-Keynote2_UserGuide.pdf-Japon
Apple-Welcome_to_Tiger.pdf-Japon
Apple-XsanAdminGuide_j.pdf-Japon
Apple-PowerBookG4_UG_15GE.PDF-Japon
Apple-Xsan_Migration.pdf-Japon
Apple-Xserve_Intel_DIY_TopCover_JA.pdf-Japon
Apple-iPod_nano_6thgen_User_Guide_J.pdf-Japon
Apple-Aperture_Photography_Fundamentals.pdf-Japon
Apple-nikeipod_users_guide.pdf-Japon
Apple-QuickTime71_UsersGuide.pdf-Japon
Apple-iMacG5_iSight_UG.pdf-Japon
Apple-Aperture_Performing_Adjustments_j.pdf-Japon
Apple-iMacG5_17inch_HardDrive.pdf-Japon
Apple-iPod_shuffle_Features_Guide_J.pdf-Japon
Apple-MacBook_Air_User_Guide.pdf-Japon
Apple-MacBook_UsersGuide.pdf-Japon
Apple-iPad_iOS4_Brukerhandbok.pdf-Norge-Norvege
Apple-Apple_AirPort_Networks_Early2009_H.pd-Norge-Norvege
Apple-iPod_classic_120GB_no.pdf-Norge-Norvege
Apple-Xserve_Intel_DIY_ExpansionCardRiser_JA.pdf-Japon
Apple-iMacG5_Battery.pdf-Japon
Apple-Logic_Pro_8_Getting_Started.pdf-Japon
Apple-PowerBook-handbok-Norge-Norveg
Apple-iWork09_formler_og_funksjoner.pdf-Norge-Norvege
Apple-MacBook_Pro_15inch_Mid2010_H.pdf-Norge-Norvege
Apple-MacPro_HardDrive_DIY.pdf-Japon
Apple-iPod_Fifth_Gen_Funksjonsoversikt.pdf-Norge-Norvege
Apple-MacBook_13inch_white_Early2009_H.pdf-Norge-Norvege
Apple-GarageBand_09_Komme_i_gang.pdf-Norge-Norvege
Apple-MacBook_Pro_15inch_Mid2009_H.pdf-Norge-Norvege
Apple-imac_mid2011_ug_h.pdf-Norge-Norvege
Apple-iDVD_08_Komme_i_gang.pdf-Norge-Norvege
Apple-MacBook_Air_11inch_Late2010_UG_H.pdf-Norge-Norvege
Apple-iMac_Mid2010_UG_H.pdf-Norge-Norvege
Apple-MacBook_13inch_Mid2009_H.pdf-Norge-Norvege
/Apple-iPhone_3G_Viktig_produktinformasjon_H-Norge-Norvege
Apple-MacBook_13inch_Mid2010_UG_H.pdf-Norge-Norvege
Apple-macbook_air_13inch_mid2011_ug_no.pdf-Norge-Norvege
Apple-Mac_mini_Early2009_UG_H.pdf-Norge-Norvege
Apple-ipad2_brukerhandbok.pdf-Norge-Norvege
Apple-iPhoto_08_Komme_i_gang.pdf-Norge-Norvege
Apple-MacBook_Air_Brukerhandbok_Late2008.pdf-Norge-Norvege
Apple-Pages09_Brukerhandbok.pdf-Norge-Norvege
Apple-MacBook_13inch_Late2009_UG_H.pdf-Norge-Norvege
Apple-iPhone_3GS_Viktig_produktinformasjon.pdf-Norge-Norvege
Apple-MacBook_13inch_Aluminum_Late2008_H.pdf-Norge-Norvege
Apple-Wireless_Keyboard_Aluminum_2007_H-Norge-Norvege
Apple-NiPod_photo_Brukerhandbok_N0190269.pdf-Norge-Norvege
Apple-MacBook_Pro_13inch_Mid2010_H.pdf-Norge-Norvege
Apple-MacBook_Pro_17inch_Mid2010_H.pdf-Norge-Norvege
Apple-Velkommen_til_Snow_Leopard.pdf-Norge-Norvege.htm
Apple-TimeCapsule_Klargjoringsoversikt.pdf-Norge-Norvege
Apple-iPhone_3GS_Hurtigstart.pdf-Norge-Norvege
Apple-Snow_Leopard_Installeringsinstruksjoner.pdf-Norge-Norvege
Apple-iMacG5_iSight_UG.pdf-Norge-Norvege
Apple-iPod_Handbok_S0342141.pdf-Norge-Norvege
Apple-ipad_brukerhandbok.pdf-Norge-Norvege
Apple-GE_Money_Bank_Handlekonto.pdf-Norge-Norvege
Apple-MacBook_Air_11inch_Late2010_UG_H.pdf-Norge-Norvege
Apple-iPod_nano_6thgen_Brukerhandbok.pdf-Norge-Norvege
Apple-iPod_touch_iOS4_Brukerhandbok.pdf-Norge-Norvege
Apple-MacBook_Air_13inch_Late2010_UG_H.pdf-Norge-Norvege
Apple-MacBook_Pro_15inch_Early2011_H.pdf-Norge-Norvege
Apple-Numbers09_Brukerhandbok.pdf-Norge-Norvege
Apple-Welcome_to_Leopard.pdf-Japon
Apple-PowerMacG5_UserGuide.pdf-Norge-Norvege
Apple-iPod_touch_2.1_Brukerhandbok.pdf-Norge-Norvege
Apple-Boot_Camp_Installering-klargjoring.pdf-Norge-Norvege
Apple-MacOSX10.3_Welcome.pdf-Norge-Norvege
Apple-iPod_shuffle_3rdGen_UG_H.pdf-Norge-Norvege
Apple-iPhone_4_Viktig_produktinformasjon.pdf-Norge-Norvege
Apple_TV_Klargjoringsoversikt.pdf-Norge-Norvege
Apple-iMovie_08_Komme_i_gang.pdf-Norge-Norvege
Apple-iPod_classic_160GB_Brukerhandbok.pdf-Norge-Norvege
Apple-Boot_Camp_Installering_10.6.pdf-Norge-Norvege
Apple-Network-Services-Location-Manager-Veiledning-for-nettverksadministratorer-Norge-Norvege
Apple-iOS_Business_Mar12_FR.pdf
Apple-PCIDualAttachedFDDICard.pdf
Apple-Aperture_Installing_Your_Software_f.pdf
Apple-User_Management_Admin_v10.4.pdf
Apple-Compressor-4-ユーザーズマニュアル Japon
Apple-Network_Services_v10.4.pdf
Apple-iPod_2ndGen_USB_Power_Adapter-DE
Apple-AirPort_Express_Opstillingsvejledning_5.1.pdf
Apple-MagSafe_Airline_Adapter.pdf
Apple-L-Apple-Multiple-Scan-20-Display
Apple-Administration_du_service_de_messagerie_10.5.pdf
Apple-iMac_Intel-based_Late2006.pdf-Japon
Apple-iPhone_3GS_Finger_Tips_J.pdf-Japon
Apple-Power-Mac-G4-Mirrored-Drive-Doors-Japon
Apple-atadrive_pmg4mdd.j.pdf-Japon
Apple-iPod_touch_2.2_User_Guide_J.pdf-Japon
Apple-Mac_OS_X_Server_v10.2.pdf
Apple-AppleCare_Protection_Plan_for_Apple_TV.pdf
Apple-DVD_Studio_Pro_4_Installation_de_votre_logiciel
Apple-PowerBookG4_17inch1.67GHzUG
Apple-iMac_Intel-based_Late2006
Apple-Installation_de_votre_logiciel
Apple-guide_des_fonctions_de_l_iPod_nano
Apple-Administration_de_serveur_v10.5
Apple-Mac-OS-X-Server-Premiers-contacts-Pour-la-version-10.3-ou-ulterieure
Apple-iBookG3_14inchUserGuideMultilingual
Apple-mac_pro_server_mid2010_ug_f
Apple-Motion_Supplemental_Documentation
Apple-iphone_guide_de_l_utilisateur
Apple-macbook_air_11inch_mid2011_ug_fr
Apple-NouvellesfonctionnalitesdeLogicExpress7.2
Apple-Mac_Pro_Early2009_4707_UG
Apple-guide_de_l_utilisateur_de_Numbers08
Apple-Guide_de_configuration_et_d'administration
Apple-mac_integration_basics_fr_106.
Apple-iPod_shuffle_4thgen_Guide_de_l_utilisateur
Apple-081811_APP_iPhone_Japanese_v5.4.pdf-Japan
Apple-Recycle_Contract120919.pdf-Japan
Apple-World_Travel_Adapter_Kit_UG
Apple-iPod_nano_6thgen_User_Guide
Apple-Mac_mini_Early2009_UG_F.pdf-Manuel-de-l-utilisateur
Apple-Compressor_3_Batch_Monitor_User_Manual_F.pdf-Manuel-de-l-utilisateur
Apple-Premiers__contacts_avec_iDVD_08
Apple-Mac_mini_Intel_User_Guide.pdf
Apple-Prise_en_charge_des_surfaces_de_controle_Logic_Express_8
Apple-mac_integration_basics_fr_107.pdf
Apple-Final-Cut-Pro-7-Niveau-1-Guide-de-preparation-a-l-examen
Apple-Logic9-examen-prep-fr.pdf-Logic-Pro-9-Niveau-1-Guide-de-preparation-a-l-examen
Apple-aperture_photography_fundamentals.pdf-Manuel-de-l-utilisateu
Apple-emac-memory.pdf-Manuel-de-l-utilisateur
Apple-Apple-Installation-et-configuration-de-votre-Power-Mac-G4
Apple-Guide_de_l_administrateur_d_Xsan_2.pdf
Apple-premiers_contacts_avec_imovie6.pdf
Apple-Tiger_Guide_Installation_et_de_configuration.pdf
Apple-Final-Cut-Pro-7-Level-One-Exam-Preparation-Guide-and-Practice-Exam
Apple-ard_admin_guide_2.2_fr.pdf
Apple-systemoverviewj.pdf-Japon
Apple-Xserve_TO_J070411.pdf-Japon
Apple-premiers_contacts_avec_iwork_08.pdf
Apple-services_de_collaboration_2e_ed_10.4.pdf
Apple-iPhone_Bluetooth_Headset_Benutzerhandbuch.pdf
Apple-Guide_de_l_utilisateur_de_Keynote08.pdf
APPLE/Apple-Logic-Pro-9-Effectsrfr.pdf
Apple-Logic-Pro-9-Effectsrfr.pdf
Apple-iPod_shuffle_3rdGen_UG_F.pdf
Apple-iPod_classic_160Go_Guide_de_l_utilisateur.pdf
Apple-iBookG4GettingStarted.pdf
Apple-Administration_de_technologies_web_10.5.pdf
Apple-Compressor-4-User-Manual-fr
Apple-MainStage-User-Manual-fr.pdf
Apple-PowerBookG4_15inch1.67-1.5GHzUserGuide.pdf
Apple-MacBook_Pro_15inch_Mid2010_CH.pdf
Apple-LED_Cinema_Display_27-inch_UG.pdf
Apple-MacBook_Pro_15inch_Mid2009_RS.pdf
Apple-macbook_pro_13inch_early2011_f.pdf
Apple-iphone_user_guide-For-iOS-6-Software
Apple-iDVD5_Getting_Started.pdf
Apple-guide_des_fonctionnalites_de_l_ipod_touch.pdf
Apple_macbook_pro_13inch_early2011_f
Apple_Guide_de_l_utilisateur_d_Utilitaire_RAID
Apple_Time_Capsule_Early2009_Setup_F
Apple_iphone_4s_finger_tips_guide_rs
apple_iphone_gebruikershandleiding
apple_apple_tv_3rd_gen_setup_tw
apple_macbook_pro-retina-mid-2012-important_product_info_ch
apple_Macintosh-User-s-Guide-for-Macintosh-PowerBook-145
Apple_ipod_touch_user_guide_ta
Apple_TV_2nd_gen_Setup_Guide_h
Apple_ipod_touch_manual_del_usuario
Apple_iphone_4s_finger_tips_guide_tu
Apple_macbook_pro_retina_qs_th
Apple-Manuel_de_l'utilisateur_de_Final_Cut_Server
Apple-Cinema_Tools_4.0_User_Manual_F
Apple-Personal-LaserWriter300-User-s-Guide
Apple-QuickTake-100-User-s-Guide-for-Macintosh
Apple-User-s-Guide-Macintosh-LC-630-DOS-Compatible
Apple-iPhone_iOS3.1_User_Guide
Apple-iphone_4s_important_product_information_guide
Apple-iPod_shuffle_Features_Guide_F
Apple-Premiers_contacts_avec_iMovie_08
Apple-macbook_pro-retina-mid-2012-important_product_info_br
Apple-macbook_pro-13-inch-mid-2012-important_product_info
Apple-macbook_air-11-inch_mid-2012-qs_br
Apple-Manuel_de_l_utilisateur_de_MainStage
Apple-Compressor_3_User_Manual_F
Apple-guide_de_configuration_airport_express_4.2
Apple-Instruments_et_effets_Logic_Express_8
Apple-Manuel_de_l_utilisateur_de_WaveBurner
Apple-Macmini_Guide_de_l'utilisateur
Disque dur, ATA parallèle Instructions de remplacement
Apple-final_cut_pro_x_logic_effects_ref_f
Apple-Leopard_Installationshandbok
Apple-thunderbolt_display_getting_started_1e
Apple-Compressor-4-Benutzerhandbuch
Apple-macbook_air_11inch_mid2011_ug
Apple-macbook_air-mid-2012-important_product_info_j
Apple-iPod-nano-Guide-des-fonctionnalites
Apple-iPod-nano-Guide-des-fonctionnalites
Apple-iPod-nano-Guide-de-l-utilisateur-4eme-generation
Apple-iPod-nano-Guide-de-l-utilisateur-4eme-generation
Apple-Manuel_de_l_utilisateur_d_Utilitaire_de_reponse_d_impulsion
Apple-Aperture_2_Raccourcis_clavier
Apple-livetype_2_user_manual_f
Apple-macbook_air_guide_de_l_utilisateur
Apple-MacBook_Early_2008_Guide_de_l_utilisateur
Apple-Keynote-2-Guide-de-l-utilisateur
Apple-PowerBook-User-s-Guide-for-PowerBook-computers
Apple-Macintosh-Performa-User-s-Guide-5200CD-and-5300CD
Apple-Macintosh-Performa-User-s-Guide
Apple-iPod-nano-Guide-des-fonctionnalites
Apple-iPad-User-Guide-For-iOS-5-1-Software
Apple-Boot-Camp-Guide-d-installation-et-de-configuration
Apple-iPod-nano-Guide-de-l-utilisateur-4eme-generation
Power Mac G5 Guide de l’utilisateur APPLE
Guide de l'utilisateur PAGE '08 APPLE
Guide de l'utilisateur KEYNOTE '09 APPLE
Guide de l'Utilisateur KEYNOTE '3 APPLE
Guide de l'Utilisateur UTILITAIRE RAID
Guide de l'Utilisateur Logic Studio
Power Mac G5 Guide de l’utilisateur APPLE
Guide de l'utilisateur PAGE '08 APPLE
Guide de l'utilisateur KEYNOTE '09 APPLE
Guide de l'Utilisateur KEYNOTE '3 APPLE
Guide de l'Utilisateur UTILITAIRE RAID
Guide de l'Utilisateur Logic Studio
Guide de l’utilisateur ipad Pour le logiciel iOS 5.1
PowerBook G4 Premiers Contacts APPLE
Guide de l'Utilisateur iphone pour le logiciel ios 5.1 APPLE
Guide de l’utilisateur ipad Pour le logiciel iOS 4,3
Guide de l’utilisateur iPod nano 5ème génération
Guide de l'utilisateur iPod Touch 2.2 APPLE
Guide de l’utilisateur QuickTime 7 Mac OS X 10.3.9 et ultérieur Windows XP et Windows 2000
Guide de l'utilisateur MacBook 13 pouces Mi 2010
Guide de l’utilisateur iPhone (Pour les logiciels iOS 4.2 et 4.3)
Guide-de-l-utilisateur-iPod-touch-pour-le-logiciel-ios-4-3-APPLE
Guide-de-l-utilisateur-iPad-2-pour-le-logiciel-ios-4-3-APPLE
Guide de déploiement en entreprise iPhone OS
Guide-de-l-administrateur-Apple-Remote-Desktop-3-1
Guide-de-l-utilisateur-Apple-Xserve-Diagnostics-Version-3X103
Guide-de-configuration-AirPort-Extreme-802.11n-5e-Generation
Guide-de-configuration-AirPort-Extreme-802-11n-5e-Generation
Guide-de-l-utilisateur-Capteur-Nike-iPod
Guide-de-l-utilisateur-iMac-21-5-pouces-et-27-pouces-mi-2011-APPLE
Guide-de-l-utilisateur-Apple-Qadministrator-4
Guide-d-installation-Apple-TV-3-eme-generation
User-Guide-iPad-For-ios-5-1-Software
Event Handling Guide
for iOSContents
About Events in iOS 6
At a Glance 6
An Application Receives Multitouch Events When Users Touch its Views 6
An Application Receives Motion Events When Users Move the Device 7
Remote-Control Events Are Sent When Users Manipulate Multimedia Controls 7
How to Use this Book 7
See Also 8
Event Types and Delivery 9
UIKit Event Objects and Types 9
Event Delivery 11
Responder Objects and the Responder Chain 11
Motion Event Types 14
Multitouch Events 16
Events and Touches 17
Approaches for Handling Touch Events 18
Regulating Touch Event Delivery 19
Handling Multitouch Events 20
The Event-Handling Methods 20
Basics of Touch-Event Handling 21
Handling Tap Gestures 24
Handling Swipe and Drag Gestures 27
Handling a Complex Multitouch Sequence 29
Hit-Testing 33
Forwarding Touch Events 35
Handling Events in Subclasses of UIKit Views and Controls 37
Best Practices for Handling Multitouch Events 37
Gesture Recognizers 39
Gesture Recognizers Simplify Event Handling 39
Recognized Gestures 39
Gestures Recognizers Are Attached to a View 40
Gestures Trigger Action Messages 41
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
2Discrete Gestures and Continuous Gestures 41
Implementing Gesture Recognition 42
Preparing a Gesture Recognizer 43
Responding to Gestures 44
Interacting with Other Gesture Recognizers 46
Requiring a Gesture Recognizer to Fail 46
Preventing Gesture Recognizers from Analyzing Touches 47
Permitting Simultaneous Gesture Recognition 48
Regulating the Delivery of Touches to Views 48
Default Touch-Event Delivery 48
Affecting the Delivery of Touches to Views 49
Creating Custom Gesture Recognizers 50
State Transitions 50
Implementing a Custom Gesture Recognizer 52
Motion Events 56
Shaking-Motion Events 56
Getting the Current Device Orientation 58
Setting Required Hardware Capabilities for Accelerometer and Gyroscope Events 59
Accessing Accelerometer Events Using UIAccelerometer 59
Choosing an Appropriate Update Interval 61
Isolating the Gravity Component from Acceleration Data 61
Isolating Instantaneous Motion from Acceleration Data 62
Core Motion 63
Handling Accelerometer Events Using Core Motion 65
Handling Rotation-Rate Data 68
Handling Processed Device-Motion Data 72
Remote Control of Multimedia 76
Preparing Your Application for Remote-Control Events 76
Handling Remote-Control Events 77
Document Revision History 79
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
3
ContentsFigures, Tables, and Listings
Event Types and Delivery 9
Figure 1-1 The responder chain in iOS 13
Listing 1-1 Event-type and event-subtype constants 9
Multitouch Events 16
Figure 2-1 A multitouch sequence and touch phases 17
Figure 2-2 Relationship of a UIEvent object and its UITouch objects 18
Figure 2-3 All touches for a given touch event 22
Figure 2-4 All touches belonging to a specific window 22
Figure 2-5 All touches belonging to a specific view 23
Listing 2-1 Detecting a double-tap gesture 24
Listing 2-2 Handling a single-tap gesture and a double-tap gesture 25
Listing 2-3 Tracking a swipe gesture in a view 27
Listing 2-4 Dragging a view using a single touch 28
Listing 2-5 Storing the beginning locations of multiple touches 30
Listing 2-6 Retrieving the initial locations of touch objects 30
Listing 2-7 Handling a complex multitouch sequence 31
Listing 2-8 Determining when the last touch in a multitouch sequence has ended 33
Listing 2-9 Calling hitTest: on a view’s CALayer object 34
Listing 2-10 Overriding hitTest:withEvent: 34
Listing 2-11 Forwarding touch events to “helper” responder objects 35
Gesture Recognizers 39
Figure 3-1 Path of touch objects when gesture recognizer is attached to a view 41
Figure 3-2 Discrete versus continuous gestures 42
Figure 3-3 Possible state transitions for gesture recognizers 51
Table 3-1 Gestures recognized by the gesture-recognizer classes of the UIKit framework 40
Listing 3-1 Creating and initializing discrete and continuous gesture recognizers 43
Listing 3-2 Handling pinch, pan, and double-tap gestures 44
Listing 3-3 Implementation of a “checkmark” gesture recognizer. 53
Listing 3-4 Resetting a gesture recognizer 55
Motion Events 56
Figure 4-1 Core Motion classes 64
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
4Figure 4-2 Right-hand rule 71
Table 4-1 Common update intervals for acceleration events 61
Listing 4-1 Becoming first responder 56
Listing 4-2 Handling a motion event 57
Listing 4-3 Configuring the accelerometer 60
Listing 4-4 Receiving an accelerometer event 60
Listing 4-5 Isolating the effects of gravity from accelerometer data 62
Listing 4-6 Getting the instantaneous portion of movement from accelerometer data 62
Listing 4-7 Configuring the motion manager and starting updates 66
Listing 4-8 Sampling and filtering accelerometer data 67
Listing 4-9 Creating the CMMotionManager object and setting up for gyroscope updates 70
Listing 4-10 Starting and stopping gyroscope updates 71
Listing 4-11 Starting and stopping device-motion updates 73
Listing 4-12 Getting the change in attitude prior to rendering 74
Remote Control of Multimedia 76
Listing 5-1 Preparing to receive remote-control events 76
Listing 5-2 Ending the receipt of remote-control events 77
Listing 5-3 Handling remote-control events 77
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
5
Figures, Tables, and ListingsEvents are objects sent to an application to inform it of user actions. In iOS, events can take many forms:
multitouch events, motion events—for example, from device accelerometers—and events for controlling
multimedia. (This last type of event is known as a remote-control event because it originates from a headset
or other external accessory.)
Multitouch events
Remote-control events
Accelerometer events
anApp
The UIKit and Core Motion frameworks are responsible for event propagation and delivery in iOS.
At a Glance
An Application Receives Multitouch Events When Users Touch its Views
The Multi-Touch interface of iPhones, iPads, and iPod touches generates low-level events when users touch
views of an application. The application sends these events (as UIEvent objects) to the view on which the
touches occurred. That view typically analyzes the touches represented by each event object and responds in
an appropriate manner.
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
6
About Events in iOSApplications are frequently interested in interpreting the touches a user makes as a common gesture, such as
a tap or swipe gesture. These applications can make use of UIKit classes called gesture recognizers, each of
which is designed to recognize a specific gesture.
Relevant Chapters:: “Event Types and Delivery” (page 9), “Multitouch Events” (page 16), “Gesture
Recognizers” (page 39)
An Application Receives Motion Events When Users Move the Device
Motion events come in different forms, and you can handle them using different frameworks. When users
shake the device, the UIKit delivers a UIEvent object to an application; these shaking-motion events are
gestures often used to trigger undo and redo actions. If you want your application to receive high-rate, continuous
accelerometer and gyroscope data, use the Core Motion framework. (Only certain devices have a gyroscope.)
You may also use the UIAccelerometer class to receive and handle accelerometer data.
Relevant Chapters:: “Event Types and Delivery” (page 9), “Motion Events” (page 56)
Remote-Control Events Are Sent When Users Manipulate Multimedia Controls
By conforming to an Apple-provide specification, headsets and other external accessories can send (via the
UIKit framework) remote-control events to an application capable of playing audio or video. The view hosting
the multimedia can receive the events and thereby control the audio video according to the user’s command
(for example, pausing or fast-forwarding).
Relevant Chapters:: “Event Types and Delivery” (page 9), “Remote Control of Multimedia” (page
76)
How to Use this Book
Regardless of the type of event you’re interested in, you should first read “Event Types and Delivery” (page
9). This chapter provides essential background information.
About Events in iOS
How to Use this Book
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
7See Also
Some iPhones and other devices have GPS and compass hardware that also generate low-level data delivered
to an application for processing. Location Awareness Programming Guide discusses how to receive and handle
this data.
Many sample code projects in the iOS Reference Library have code that illustrates the handling of multitouch
events and the use of gesture recognizers. Among these are the following projects: Touches, CopyPasteTile ,
and SimpleGestureRecognizers.
About Events in iOS
See Also
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
8An iPhone, iPad, or iPod touch device has multiple items of hardware that generate streams of input data an
application can access. The Multi-Touch technology enables the direct manipulation of views, including the
virtual keyboard. Three accelerometers measure acceleration along the three spatial axes. A gyroscope (only
on some device models) measures the rate of rotation around the three axes. The Global Positioning System
(GPS) and compass provide measurements of location and orientation. Each of these hardware systems, as
they detect touches, device movements, and location changes, produce raw data that is passed to system
frameworks. The frameworks package the data and deliver them as events to an application for processing.
The following sections identify these frameworks and describe how events are packaged and delivered to
applications for handling.
Note: This document describes touch events, motion events, and remote control events only. For
information on handling GPS and magnetometer (compass) data, see Location Awareness
Programming Guide .
UIKit Event Objects and Types
An event is an object that represents a user action detected by hardware on the device and conveyed to
iOS—for example, a finger touching the screen or hand shaking the device. Many events are instances of the
UIEvent class of the UIKit framework. A UIEvent object may encapsulate state related to the user event,such
asthe associated touches. It also recordsthe moment the event was generated. As a user action takes place—for
example, as fingers touch the screen and move across its surface—the operating system continually sends
event objects to an application for handling.
UIKit currently recognizes three types of events: touch events, “shaking” motion events, and remote-control
events. The UIEvent class declares the enum constants shown in Listing 1-1.
Listing 1-1 Event-type and event-subtype constants
typedef enum {
UIEventTypeTouches,
UIEventTypeMotion,
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
9
Event Types and DeliveryUIEventTypeRemoteControl,
} UIEventType;
typedef enum {
UIEventSubtypeNone = 0,
UIEventSubtypeMotionShake = 1,
UIEventSubtypeRemoteControlPlay = 100,
UIEventSubtypeRemoteControlPause = 101,
UIEventSubtypeRemoteControlStop = 102,
UIEventSubtypeRemoteControlTogglePlayPause = 103,
UIEventSubtypeRemoteControlNextTrack = 104,
UIEventSubtypeRemoteControlPreviousTrack = 105,
UIEventSubtypeRemoteControlBeginSeekingBackward = 106,
UIEventSubtypeRemoteControlEndSeekingBackward = 107,
UIEventSubtypeRemoteControlBeginSeekingForward = 108,
UIEventSubtypeRemoteControlEndSeekingForward = 109,
} UIEventSubtype;
Each event has one of these event type and subtype constants associated with it, which you can accessthrough
the type and subtype properties of UIEvent. The event type includes touch events, motion events, and
remote control events. In iOS 3.0, there is a shake-motion subtype (UIEventSubtypeMotionShake) and
many remote-control subtypes; touch events always have a subtype of UIEventSubtypeNone.
A remote-control event originates as commands from the system transport controls or an external accessory
conforming to an Apple-provided specification, such as a headset. They are intended to allow users to control
multimedia content using those controls and external accessories. Remote-control events are new with iOS
4.0 and are described in detail in “Remote Control of Multimedia” (page 76).
You should never retain a UIEvent object in your code. If you need to preserve the current state of an event
object for later evaluation, you should copy and store those bits of state in an appropriate manner (using an
instance variable or a dictionary object, for example).
A device running iOS can send other types of events, broadly considered, to an application for handling. These
events are not UIEvent objects, but still encapsulate a measurement of some hardware-generated values.
“Motion Event Types” (page 14) discusses these other events.
Event Types and Delivery
UIKit Event Objects and Types
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
10Event Delivery
The delivery of an event to an object for handling occurs along a specific path. As described in “Preparing Your
Application for Remote-Control Events” (page 76), when users touch the screen of a device, iOS recognizes
the set of touches and packages them in a UIEvent object that it places in the active application’s event queue.
If the system interprets the shaking of the device as a motion event, an event object representing that event
is also placed in the application’s event queue. The singleton UIApplication object managing the application
takes an event from the top of the queue and dispatches it for handling. Typically, it sends the event to the
application’s key window—the window currently the focusfor user events—and the window object representing
that window sends the event to an initial object for handling. That object is different for touch events and
motion events.
● Touch events. The window object uses hit-testing and the responder chain to find the view to receive the
touch event. In hit-testing, a window calls hitTest:withEvent: on the top-most view of the view
hierarchy; this method proceeds by recursively calling pointInside:withEvent: on each view in the
view hierarchy that returns YES, proceeding down the hierarchy until it finds the subview within whose
bounds the touch took place. That view becomes the hit-test view.
If the hit-test view cannot handle the event, the event travels up the responder chain as described in
“Responder Objects and the Responder Chain” (page 11) until the system finds a view that can handle it.
A touch object (described in “Events and Touches” (page 17)) is associated with its hit-test view for its
lifetime, even if the touch represented by the object subsequently moves outside the view.
“Hit-Testing” (page 33) discusses some of the programmatic implications of hit-testing.
● Motion and remote-control events. The window object sends each shaking-motion or remote-control
event to the first responder for handling. (The first responder is described in “Responder Objects and the
Responder Chain.”
Although the hit-test view and the first responder are often the same view object, they do not have to be the
same.
The UIApplication object and each UIWindow object dispatches eventsin the sendEvent: method. (These
classes declare a method with the same signature). Because these methods are funnel pointsfor events coming
into an application, you can subclass UIApplication or UIWindow and override the sendEvent: method
to monitor events (which is something few applications would need to do). If you override these methods, be
sure to call the superclass implementation (that is, [super sendEvent:theEvent]); never tamper with the
distribution of events.
Responder Objects and the Responder Chain
The preceding discussion mentions the concept of responders. What is a responder object and how does it fit
into the architecture for event delivery?
Event Types and Delivery
Event Delivery
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
11A responder object is an object that can respond to events and handle them. UIResponder is the base class
for all responder objects, also known as, simply, responders. It defines the programmatic interface not only for
event handling but for common responder behavior. UIApplication, UIView, and all UIKit classes that
descend from UIView (including UIWindow) inherit directly or indirectly from UIResponder, and thus their
instances are responder objects.
The first responder is the responder object in an application (usually a UIView object) that is designated to
be the first recipient of events other than touch events. A UIWindow object sends the first responder these
events in messages, giving it the first shot at handling them. To receive these messages, the responder object
must implement canBecomeFirstResponder to return YES; it must also receive a becomeFirstResponder
message (which it can invoke on itself). The first responder isthe first view in a window to receive the following
type of events and messages:
● Motion events—via calls to the UIResponder motion-handling methods described in “Shaking-Motion
Events” (page 56)
● Remote-control events—via calls to the UIResponder method remoteControlReceivedWithEvent:
● Action messages—sent when the user manipulates a control (such as a button or slider) and no target is
specified for the action message
● Editing-menu messages—sent when userstap the commands of the editing menu (described in “Displaying
and Managing the Edit Menu”)
The first responder also plays a role in text editing. A text view or text field that is the focus of editing is made
the first responder, which causes the virtual keyboard to appear.
Note: Applications must explicitly set a first responder to handle motion events, action messages,
and editing-menu messages; UIKit automatically sets the text field or text view a user taps to be the
first responder.
If the first responder or the hit-test view doesn’t handle an event, UIKit may pass the event (via message) to
the next responder in the responder chain to see if it can handle it.
The responder chain is a linked series of responder objects along which an event, action message, or
editing-menu message is passed. It allows responder objects to transfer responsibility for handling an event
to other, higher-level objects. An event proceeds up the responder chain as the application looks for an object
Event Types and Delivery
Event Delivery
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
12capable of handling the event. Because the hit-test view is also a responder object, an application may also
take advantage of the responder chain when handing touch events. The responder chain consists of a series
of next responders (each returned by the nextResponder method) in the sequence depicted in Figure 1-1.
Figure 1-1 The responder chain in iOS
superview
window
View
View
View
UIApplication
View controller
Window
superview
When the system delivers a touch event, it first sends it to a specific view. For touch events, that view is the
one returned by hitTest:withEvent:; for “shaking”-motion events, remote-control events, action messages,
and editing-menu messages, that view is the first responder. If the initial view doesn’t handle the event, it
travels up the responder chain along a particular path:
1. The hit-test view or first responder passes the event or message to its view controller if it has one; if the
view doesn’t have a view controller, it passes the event or message to its superview.
2. If a view or its view controller cannot handle the event or message, it passes it to the superview of the view.
3. Each subsequentsuperview in the hierarchy followsthe pattern described in the first two stepsif it cannot
handle the event or message.
4. The topmost view in the view hierarchy, if it doesn’t handle the event or message, passes it to the window
object for handling.
5. The UIWindow object, if it doesn’t handle the event or message, passesit to the singleton application object.
If the application object cannot handle the event or message, it discards it.
If you implement a custom view to handle “shaking”-motion events, remote-control events, action messages,
or editing-menu messages, you should not forward the event or message to nextResponder directly to send
it up the responder chain. Instead invoke the superclass implementation of the current event-handling
method—let UIKit handle the traversal of the responder chain.
Event Types and Delivery
Event Delivery
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
13Motion Event Types
Motion events come from two hardware sources on a device: the three accelerometers and the gyroscope,
which is available only some devices. An accelerometer measures changes in velocity over time along a given
linear path. The combination of accelerometers lets you detect movement of the device in any direction. You
can use this data to track both sudden movements in the device and the device’s current orientation relative
to gravity. A gyroscope measures the rate of rotation around each of the three axes. (Although there are three
accelerometers, one for each axis, the remainder of this document refers to them as a single entity.)
The Core Motion framework is primarily responsible for accessing raw accelerometer and gyroscope data and
feeding that data to an application for handling. In addition, Core Motion processes combined accelerometer
and gyroscope data using special algorithms and presents that refined motion data to applications. Motion
eventsfrom Core Motion are represented by three data objects, each encapsulating one or more measurements:
● A CMAccelerometerData object encapsulates a structure that captures the acceleration along each of
the spatial axes.
● A CMGyroData object encapsulates a structure that captures the rate of rotation around each of the three
spatial axes.
● A CMDeviceMotion object encapsulates several different measurements, including attitude and more
useful measurements of rotation rate and acceleration.
Core Motion is apart from UIKit architectures and conventions. There is no connection with the UIEvent model
and there is no notion of first responder or responder chain. It delivers motion events directly to applications that
request them.
The CMMotionManager class is the central access point for Core Motion. You create an instance of the class,
specify an update interval (either explicitly or implicitly), request that updates start, and handle the motion
events as they are delivered. “Core Motion” (page 63) describes this procedure in full detail.
An alternative to Core Motion, at least for accessing accelerometer data, is the UIAccelerometer class of the
UIKit framework. When you use this class, accelerometer events are delivered as UIAcceleration objects.
Although UIAccelerometer is part of UIKit, it is also separate from the UIEvent and responder-chain
architectures. See “Accessing Accelerometer Events Using UIAccelerometer” (page 59) for information on using
the UIKit facilities.
Event Types and Delivery
Motion Event Types
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
14Notes: The UIAccelerometer and UIAcceleration classes will be deprecated in a future release,
so if your application handles accelerometer events, it should transition to the Core Motion API.
In iOS 3.0 and later, if you are trying to detect specific types of motion as gestures—specifically
shaking motions—you should consider handling motion events (UIEventTypeMotion) instead of
using the accelerometer interfaces. If you want to receive and handle high-rate, continuous motion
data, you should instead use the Core Motion accelerometer API. Motion events are described in
“Shaking-Motion Events” (page 56).
Event Types and Delivery
Motion Event Types
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
15Note: This chapter contains information that used to be in iOS App Programming Guide . The
information in this chapter has not been updated specifically for iOS 4.0.
Touch events in iOS are based on a Multi-Touch model. Instead of using a mouse and a keyboard, users touch
the screen of the device to manipulate objects, enter data, and otherwise convey their intentions. iOS recognizes
one or more fingers touching the screen as part of a multitouch sequence . This sequence begins when the first
finger touches down on the screen and ends when the last finger is lifted from the screen. iOS tracks fingers
touching the screen throughout a multitouch sequence and records the characteristics of each of them,
including the location of the finger on the screen and the time the touch occurred. Applications often recognize
certain combinations of touches as gestures and respond to them in ways that are intuitive to users, such as
zooming in on content in response to a pinching gesture and scrolling through content in response to a flicking
gesture.
Notes: A finger on the screen affords a much different level of precision than a mouse pointer. When
a user touches the screen, the area of contact is actually elliptical and tends to be offset below the
point where the user thinks he or she touched. This “contact patch” also varies in size and shape
based on which finger is touching the screen, the size of the finger, the pressure of the finger on the
screen, the orientation of the finger, and other factors. The underlying Multi-Touch system analyzes
all of this information for you and computes a single touch point.
iOS 4.0 still reports touches on iPhone 4 (and on future high-resolution devices) in a 320x480
coordinate space to maintain source compatibility, but the resolution is twice as high in each
dimension for applications built for iOS 4.0 and later releases. In concrete terms, that means that
touchesfor applications built for iOS 4 running on iPhone 4 can land on half-point boundaries where
on older devices they land only on full point boundaries. If you have any round-to-integer code in
your touch-handling path you may lose this precision.
Many classes in UIKit handle multitouch events in ways that are distinctive to objects of the class. This is
especially true of subclasses of UIControl, such as UIButton and UISlider. Objects of these
subclasses—known as control objects—are receptive to certain types of gestures, such as a tap or a drag in a
certain direction; when properly configured, they send an action message to a target object when that gesture
occurs. Other UIKit classes handle gestures in other contexts; for example, UIScrollView provides scrolling
behavior for table views, text views, and other views with large content areas.
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
16
Multitouch EventsSome applications may not need to handle events directly; instead, they can rely on the classes of UIKit for
that behavior. However, if you create a custom subclass of UIView—a common pattern in iOS development—and
if you want that view to respond to certain touch events, you need to implement the code required to handle
those events. Moreover, if you want a UIKit object to respond to events differently, you have to create a subclass
of that framework class and override the appropriate event-handling methods.
Events and Touches
In iOS, a touch is the presence or movement of a finger on the screen that is part of a unique multitouch
sequence. For example, a pinch-close gesture has two touches: two fingers on the screen moving toward each
other from opposite directions. There are simple single-finger gestures, such as a tap, or a double-tap, a drag,
or a flick (where the user quickly swipes a finger across the screen). An application might recognize even more
complicated gestures; for example, an application might have a custom control in the shape of a dial that users
“turn” with multiple fingers to fine-tune some variable.
A UIEvent object of type UIEventTypeTouches represents a touch event. The system continually sends
these touch-event objects (or simply, touch events) to an application as fingers touch the screen and move
acrossitssurface. The event provides a snapshot of all touches during a multitouch sequence, most importantly
the touchesthat are new or have changed for a particular view. As depicted in Figure 2-1, a multitouch sequence
begins when a finger first touches the screen. Other fingers may subsequently touch the screen, and all fingers
may move across the screen. The sequence ends when the last of these fingers is lifted from the screen. An
application receives event objects during each phase of any touch.
Figure 2-1 A multitouch sequence and touch phases
UITouchPhaseBegan UITouchPhaseEnded
Touch 1
down
UITouchPhaseBegan
Touch 2
down
UITouchPhaseMoved
Touch 1 and 2
moved
Touch 1 and 2
up
Touches, which are represented by UITouch objects, have both temporal and spatial aspects. The temporal
aspect, called a phase, indicates when a touch has just begun, whether it is moving or stationary, and when it
ends—that is, when the finger is lifted from the screen.
Multitouch Events
Events and Touches
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
17The spatial aspect of touches concerns their association with the object in which they occur as well as their
location in it. When a finger touches the screen, the touch is associated with the underlying window and view
and maintains that association throughout the life of the event. If multiple touches arrive at once, they are
treated together only if they are associated with the same view. Likewise, if two touches arrive in quick
succession, they are treated as a multiple tap only if they are associated with the same view. A touch object
stores the current location and previous location (if any) of the touch in its view or window.
An event object contains all touch objects for the current multitouch sequence and can provide touch objects
specific to a view or window (see Figure 2-2). A touch object is persistent for a given finger during a sequence,
and UIKit mutates it as it tracks the finger throughout it. The touch attributes that change are the phase of the
touch, its location in a view, its previous location, and its timestamp. Event-handling code may evaluate these
attributes to determine how to respond to a touch event.
Figure 2-2 Relationship of a UIEvent object and its UITouch objects
UIEvent
UITouch
phase = UITouchPhaseBegan
locationInView = (35,50)
view = ViewA
phase = UITouchPhaseMoved
locationInView = (35,20)
view = ViewA
UITouch
phase = UITouchPhaseEnded
locationInView = (120,87)
view = ViewB
UITouch
Because the system can cancel a multitouch sequence at any time, an event-handling application must be
prepared to respond appropriately. Cancellations can occur as a result of overriding system events, such as an
incoming phone call.
Approaches for Handling Touch Events
Most applications that are interested in users’ touches on their custom views are interested in detecting and
handling well-established gestures. These gestures include tapping (one or multiple times), pinching (to zoom
a view in or out), swiping , panning or dragging a view, and using two fingers to rotate a view.
You could implement the touch-event handling code to recognize and handle these gestures, but that code
would be complex, possibly buggy, and take some time to write. Alternatively, you could simplify the
interpretation and handling of common gestures by using one of the gesture recognizer classes introduced
in iOS 3.2. To use a gesture recognizer, you instantiate it, attach it to the view receiving touches, configure it,
and assign it an action selector and a target object. When the gesture recognizer recognizes its gesture, it sends
an action message to the target, allowing the target to respond to the gesture.
Multitouch Events
Approaches for Handling Touch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
18You can implement a custom gesture recognizer by subclassing UIGestureRecognizer. A custom gesture
recognizer requires you to analyze the stream of events in a multitouch sequence to recognize your distinct
gesture; to do this, you should be familiar with the information in this chapter.
For information about gesture recognizers, see “Gesture Recognizers” (page 39).
Regulating Touch Event Delivery
UIKit gives applications programmatic means to simplify event handling or to turn off the stream of UIEvent
objects completely. The following list summarizes these approaches:
● Turning off delivery of touch events. By default, a view receives touch events, but you can set its
userInteractionEnabled property to NO to turn off delivery of touch events. A view also does not
receive these events if it’s hidden or if it’s transparent.
● Turning off delivery of touch events for a period. An application can call the UIApplication method
beginIgnoringInteractionEvents and later call the endIgnoringInteractionEvents method.
The first method stops the application from receiving touch events entirely; the second method is called
to resume the receipt of such events. You sometimes want to turn off event delivery while your code is
performing animations.
● Turning on delivery of multiple touches. By default, a view ignores all but the first touch during a
multitouch sequence. If you want the view to handle multiple touches you must enable this capability for
the view. You do this programmatically by setting the multipleTouchEnabled property of your view
to YES, or in Interface Builder by setting the related attribute in the inspector for the related view.
● Restricting event delivery to a single view. By default, a view’s exclusiveTouch property is set to NO,
which means that this view does not block other views in a window from receiving touches. If you set the
property to YES, you mark the view so that, if it is tracking touches, it is the only view in the window that
is tracking touches. Other views in the window cannot receive those touches. However, a view that is
marked “exclusive touch” does not receive touches that are associated with other views in the same
window. If a finger contacts an exclusive-touch view, then that touch is delivered only if that view is the
only view tracking a finger in that window. If a finger touches a non-exclusive view, then that touch is
delivered only if there is not another finger tracking in an exclusive-touch view.
● Restricting event delivery to subviews. A custom UIView class can override hitTest:withEvent: to
restrict the delivery of multitouch events to its subviews. See “Hit-Testing” (page 33) for a discussion of
this technique.
Multitouch Events
Regulating Touch Event Delivery
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
19Handling Multitouch Events
To handle multitouch events, you must first create a subclass of a responder class. This subclass could be any
one of the following:
● A custom view (subclass of UIView)
● A subclass of UIViewController or one of its UIKit subclasses
● A subclass of a UIKit view or control class, such as UIImageView or UISlider
● A subclass of UIApplication or UIWindow (although this would be rare)
A view controller typically receives, via the responder chain, touch events initially sent to its view if that view
does not override the touch-handling methods.
For instances of your subclass to receive multitouch events, your subclass must implement one or more of the
UIResponder methods for touch-event handling, described below. In addition, the view must be visible
(neither transparent or hidden) and must have its userInteractionEnabled property set to YES, which is
the default.
The following sections describe the touch-event handling methods, describe approachesfor handling common
gestures, show an example of a responder object that handles a complex sequence of multitouch events,
discuss event forwarding, and suggest some techniques for event handling.
The Event-Handling Methods
During a multitouch sequence, the application dispatches a series of event messages to the target responder.
To receive and handle these messages, the class of a responder object must implement at least one of the
following methods declared by UIResponder, and, in some cases, all of these methods:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
The application sends these messages when there are new or changed touches for a given touch phase:
●
Itsendsthe touchesBegan:withEvent: message when one or more fingerstouch down on the screen.
●
It sends the touchesMoved:withEvent: message when one or more fingers move.
●
It sends the touchesEnded:withEvent: message when one or more fingers lift up from the screen.
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
20●
It sends the touchesCancelled:withEvent: message when the touch sequence is cancelled by a
system event, such as an incoming phone call.
Each of these methodsis associated with a touch phase; for example, touchesBegan:withEvent: is associated
with UITouchPhaseBegan. You can get the phase of any UITouch object by evaluating its phase property.
Each message that invokes an event-handling method passes in two parameters. The first is a set of UITouch
objectsthat represent new or changed touchesfor the given phase. The second parameter is a UIEvent object
representing this particular event. From the event object you can get all touch objectsfor the event or a subset
of those touch objects filtered for specific views or windows. Some of these touch objects represent touches
that have not changed since the previous event message or that have changed but are in different phases.
Basics of Touch-Event Handling
You frequently handle an event for a given phase by getting one or more of the UITouch objects in the
passed-in set, evaluating their properties or getting their locations, and proceeding accordingly. The objects
in the set represent those touchesthat are new or have changed for the phase represented by the implemented
event-handling method. If any of the touch objects will do, you can send the NSSet object an anyObject
message; this is the case when the view receives only the first touch in a multitouch sequence (that is, the
multipleTouchEnabled property is set to NO).
An important UITouch method is locationInView:, which, if passed a parameter of self, yieldsthe location
of the touch in the coordinate system of the receiving view. A parallel method tells you the previous location
of the touch (previousLocationInView:). Properties of the UITouch instance tell you how many taps have
been made (tapCount), when the touch was created or last mutated (timestamp), and what phase it is in
(phase).
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
21If for some reason you are interested in touches in the current multitouch sequence that have not changed
since the last phase or that are in a phase other than the ones in the passed-in set, you can request them from
the passed-in UIEvent object. The diagram in Figure 2-3 depicts a UIEvent object that contains four touch
objects. To get all these touch objects, you would invoke the allTouches on the event object.
Figure 2-3 All touches for a given touch event
Window B
Window A
UIEvent
UITouch
UITouch
UITouch
UITouch
View C
View A
View B
If on the other hand you are interested in only those touches associated with a specific window (Window A in
Figure 2-4), you would send the UIEvent object a touchesForWindow: message.
Figure 2-4 All touches belonging to a specific window
Window B
Window A
UIEvent
UITouch
UITouch
UITouch
UITouch
View C
View A
View B
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
22If you want to get the touches associated with a specific view, you would call touchesForView: on the event
object, passing in the view object (View A in Figure 2-5).
Figure 2-5 All touches belonging to a specific view
Window B
Window A
UIEvent
UITouch
UITouch
UITouch
UITouch
View C
View A
View B
If a responder creates persistent objects while handling events during a multitouch sequence, it should
implement touchesCancelled:withEvent: to dispose ofthose objects when the system cancelsthe sequence.
Cancellation often occurs when an external event—for example, an incoming phone call—disruptsthe current
application’s event processing. Note that a responder object should also dispose of those same objects when
it receivesthe last touchesEnded:withEvent: message for a multitouch sequence. (See “Forwarding Touch
Events” (page 35) to find out how to determine the last UITouchPhaseEnded touch object in a multitouch
sequence.)
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
23Important: If your custom responder class is a subclass of UIView or UIViewController, you should
implement all of the methods described in “The Event-Handling Methods” (page 20). If your class is a
subclass of any other UIKit responder class, you do not need to override all of the event-handling methods;
however, in those methods that you do override, be sure to call the superclass implementation of the
method (for example, super touchesBegan:touches withEvent:theEvent];). The reason for this
guideline issimple: All viewsthat processtouches, including your own, expect (orshould expect) to receive
a full touch-eventstream. If you prevent a UIKit responder object from receiving touchesfor a certain phase
of an event, the resulting behavior may be undefined and probably undesirable.
Handling Tap Gestures
A very common gesture in iOS applications is the tap: the user taps an object on the screen with his or her
finger. A responder object can handle a single tap in one way, a double-tap in another, and possibly a triple-tap
in yet another way. To determine the number of times the user tapped a responder object, you get the value
of the tapCount property of a UITouch object.
The best places to find this value are the methods touchesBegan:withEvent: and
touchesEnded:withEvent:. In many cases, the latter method is preferred because it corresponds to the
touch phase in which the user lifts a finger from a tap. By looking for the tap count in the touch-up phase
(UITouchPhaseEnded), you ensure that the finger is really tapping and not, for instance, touching down and
then dragging.
Listing 2-1 shows how to determine whether a double-tap occurred in one of your views.
Listing 2-1 Detecting a double-tap gesture
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
if (touch.tapCount >= 2) {
[self.superview bringSubviewToFront:self];
}
}
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
24}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
}
A complication arises when a responder object wants to handle a single-tap and a double-tap gesture in
different ways. For example, a single tap might select the object and a double tap might display a view for
editing the item that was double-tapped. How is the responder object to know that a single tap is not the first
part of a double tap? Listing 2-2 (page 25) illustrates an implementation of the event-handling methods that
increases the size of the receiving view upon a double-tap gesture and decreases it upon a single-tap gesture.
The following is a commentary on this code:
1. In touchesEnded:withEvent:, when the tap count is one, the responder object sends itself a
performSelector:withObject:afterDelay: message. The selector identifies another method
implemented by the responder to handle the single-tap gesture; the second parameter is an NSValue or
NSDictionary object that holdssome state of the UITouch object; the delay issome reasonable interval
between a single- and a double-tap gesture.
Note: Because a touch object is mutated as it proceeds through a multitouch sequence, you
cannot retain a touch and assume that itsstate remainsthe same. (And you cannot copy a touch
object because UITouch does not adopt the NSCopying protocol.) Thusif you want to preserve
the state of a touch object, you should store those bits ofstate in a NSValue object, a dictionary,
or a similar object. (The code in Listing 2-2 stores the location of the touch in a dictionary but
does not use it; this code is included for purposes of illustration.)
2. In touchesBegan:withEvent:, if the tap count is two, the responder object cancels the pending
delayed-perform invocation by calling the cancelPreviousPerformRequestsWithTarget: method
of NSObject, passing itself as the argument. If the tap count is not two, the method identified by the
selector in the previous step for single-tap gestures is invoked after the delay.
3. In touchesEnded:withEvent:, if the tap count is two, the responder performs the actions necessary
for handling double-tap gestures.
Listing 2-2 Handling a single-tap gesture and a double-tap gesture
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
if (aTouch.tapCount == 2) {
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
25[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
if (theTouch.tapCount == 1) {
NSDictionary *touchLoc = [NSDictionary dictionaryWithObject:
[NSValue valueWithCGPoint:[theTouch locationInView:self]]
forKey:@"location"];
[self performSelector:@selector(handleSingleTap:) withObject:touchLoc
afterDelay:0.3];
} else if (theTouch.tapCount == 2) {
// Double-tap: increase image size by 10%"
CGRect myFrame = self.frame;
myFrame.size.width += self.frame.size.width * 0.1;
myFrame.size.height += self.frame.size.height * 0.1;
myFrame.origin.x -= (self.frame.origin.x * 0.1) / 2.0;
myFrame.origin.y -= (self.frame.origin.y * 0.1) / 2.0;
[UIView beginAnimations:nil context:NULL];
[self setFrame:myFrame];
[UIView commitAnimations];
}
}
- (void)handleSingleTap:(NSDictionary *)touches {
// Single-tap: decrease image size by 10%"
CGRect myFrame = self.frame;
myFrame.size.width -= self.frame.size.width * 0.1;
myFrame.size.height -= self.frame.size.height * 0.1;
myFrame.origin.x += (self.frame.origin.x * 0.1) / 2.0;
myFrame.origin.y += (self.frame.origin.y * 0.1) / 2.0;
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
26[UIView beginAnimations:nil context:NULL];
[self setFrame:myFrame];
[UIView commitAnimations];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
/* no state to clean up, so null implementation */
}
Handling Swipe and Drag Gestures
Horizontal and vertical swipes are a simple type of gesture that you can track easily from your own code and
use to perform actions. To detect a swipe gesture, you have to track the movement of the user’s finger along
the desired axis of motion, but it is up to you to determine what constitutes a swipe. In other words, you need
to determine whether the user’s finger moved far enough, if it moved in a straight enough line, and if it went
fast enough. You do that by storing the initial touch location and comparing it to the location reported by
subsequent touch-moved events.
Listing 2-3 shows some basic tracking methods you could use to detect horizontal swipes in a view. In this
example, the view stores the initial location of the touch in a startTouchPosition instance variable. As the
user’sfinger moves, the code comparesthe current touch location to the starting location to determine whether
it is a swipe. If the touch moves too far vertically, it is not considered to be a swipe and is processed differently.
If it continues along its horizontal trajectory, however, the code continues processing the event as if it were a
swipe. The processing routines could then trigger an action once the swipe had progressed far enough
horizontally to be considered a complete gesture. To detect swipe gestures in the vertical direction, you would
use similar code but would swap the x and y components.
Listing 2-3 Tracking a swipe gesture in a view
#define HORIZ_SWIPE_DRAG_MIN 12
#define VERT_SWIPE_DRAG_MAX 4
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// startTouchPosition is an instance variable
startTouchPosition = [touch locationInView:self];
}
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
27- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self];
// To be a swipe, direction of touch must be horizontal and long enough.
if (fabsf(startTouchPosition.x - currentTouchPosition.x) >= HORIZ_SWIPE_DRAG_MIN
&&
fabsf(startTouchPosition.y - currentTouchPosition.y) <= VERT_SWIPE_DRAG_MAX)
{
// It appears to be a swipe.
if (startTouchPosition.x < currentTouchPosition.x)
[self myProcessRightSwipe:touches withEvent:event];
else
[self myProcessLeftSwipe:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
startTouchPosition = CGPointZero;
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
startTouchPosition = CGPointZero;
}
Listing 2-4 shows an even simpler implementation of tracking a single touch, but this time for the purposes
of dragging the receiving view around the screen. In this instance, the responder class fully implements only
the touchesMoved:withEvent: method, and in this method computes a delta value between the touch's
current location in the view and its previouslocation in the view. It then usesthis delta value to reset the origin
of the view’s frame.
Listing 2-4 Dragging a view using a single touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
28- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
CGPoint loc = [aTouch locationInView:self];
CGPoint prevloc = [aTouch previousLocationInView:self];
CGRect myFrame = self.frame;
float deltaX = loc.x - prevloc.x;
float deltaY = loc.y - prevloc.y;
myFrame.origin.x += deltaX;
myFrame.origin.y += deltaY;
[self setFrame:myFrame];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
}
Handling a Complex Multitouch Sequence
Taps, drags, and swipes are simple gestures, typically involving only a single touch. Handling a touch event
consisting of two or more touches is a more complicated affair. You may have to track all touches through all
phases, recording the touch attributes that have changed and altering internal state appropriately. There are
a couple of things you should do when tracking and handling multiple touches:
● Set the multipleTouchEnabled property of the view to YES.
● Use a Core Foundation dictionary object (CFDictionaryRef) to track the mutations of touches through
their phases during the event.
When handling an event with multiple touches, you often store initial bits of each touch’s state for later
comparison with the mutated UITouch instance. As an example, say you want to compare the final location
of each touch with its original location. In the touchesBegan:withEvent: method, you can obtain the
original location of each touch from the locationInView: method and store those in a CFDictionaryRef
object using the addresses of the UITouch objects as keys. Then, in the touchesEnded:withEvent: method
you can use the address of each passed-in UITouch object to obtain the object’s original location and compare
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
29that with its current location. (You should use a CFDictionaryRef type rather than an NSDictionary object;
the latter copies its keys, but the UITouch class does not adopt the NSCopying protocol, which is required
for object copying.)
Listing 2-5 illustrates how you might store beginning locations of UITouch objects in a Core Foundation
dictionary.
Listing 2-5 Storing the beginning locations of multiple touches
- (void)cacheBeginPointForTouches:(NSSet *)touches
{
if ([touches count] > 0) {
for (UITouch *touch in touches) {
CGPoint *point = (CGPoint *)CFDictionaryGetValue(touchBeginPoints,
touch);
if (point == NULL) {
point = (CGPoint *)malloc(sizeof(CGPoint));
CFDictionarySetValue(touchBeginPoints, touch, point);
}
*point = [touch locationInView:view.superview];
}
}
}
Listing 2-6 illustrates how to retrieve those initial locations stored in the dictionary. It also gets the current
locations of the same touches. It uses these values in computing an affine transformation (not shown).
Listing 2-6 Retrieving the initial locations of touch objects
- (CGAffineTransform)incrementalTransformWithTouches:(NSSet *)touches {
NSArray *sortedTouches = [[touches allObjects]
sortedArrayUsingSelector:@selector(compareAddress:)];
// other code here ...
UITouch *touch1 = [sortedTouches objectAtIndex:0];
UITouch *touch2 = [sortedTouches objectAtIndex:1];
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
30CGPoint beginPoint1 = *(CGPoint *)CFDictionaryGetValue(touchBeginPoints,
touch1);
CGPoint currentPoint1 = [touch1 locationInView:view.superview];
CGPoint beginPoint2 = *(CGPoint *)CFDictionaryGetValue(touchBeginPoints,
touch2);
CGPoint currentPoint2 = [touch2 locationInView:view.superview];
// compute the affine transform...
}
Although the code example in Listing 2-7 doesn’t use a dictionary to track touch mutations, it also handles
multiple touches during an event. It shows a custom UIView object responding to touches by animating the
movement of a “Welcome” placard around the screen as a finger moves it and changing the language of the
welcome when the user makes a double-tap gesture. (The code in this example comes from the MoveMe
sample code project, which you can examine to get a better understanding of the event-handling context.)
Listing 2-7 Handling a complex multitouch sequence
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
// Only move the placard view if the touch was in the placard view
if ([touch view] != placardView) {
// On double tap outside placard view, update placard's display string
if ([touch tapCount] == 2) {
[placardView setupNextDisplayString];
}
return;
}
// "Pulse" the placard view by scaling up then down
// Use UIView's built-in animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGAffineTransform transform = CGAffineTransformMakeScale(1.2, 1.2);
placardView.transform = transform;
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
31[UIView setAnimationDuration:0.5];
transform = CGAffineTransformMakeScale(1.1, 1.1);
placardView.transform = transform;
[UIView commitAnimations];
// Move the placardView to under the touch
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
placardView.center = [self convertPoint:[touch locationInView:self]
fromView:placardView];
[UIView commitAnimations];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
// If the touch was in the placardView, move the placardView to its location
if ([touch view] == placardView) {
CGPoint location = [touch locationInView:self];
location = [self convertPoint:location fromView:placardView];
placardView.center = location;
return;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
// If the touch was in the placardView, bounce it back to the center
if ([touch view] == placardView) {
// Disable user interaction so subsequent touches don't interfere with
animation
self.userInteractionEnabled = NO;
[self animatePlacardViewToCenter];
return;
}
}
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
32Note: Custom views that redraw themselves in response to events they handle generally should
only set drawing state in the event-handling methods and perform all of the drawing in the
drawRect: method. To learn more about drawing view content, see View Programming Guide for
iOS .
To find out when the last finger in a multitouch sequence islifted from a view, compare the number of UITouch
objects in the passed-in set with the number of touches for the view maintained by the passed-in UIEvent
object. If they are the same, then the multitouch sequence has concluded. Listing 2-8 illustrates how to do this
in code.
Listing 2-8 Determining when the last touch in a multitouch sequence has ended
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
if ([touches count] == [[event touchesForView:self] count]) {
// last finger has lifted....
}
}
Remember that the passed-in set contains all touch objects associated with the receiving view that are new
or changed for the given phase whereas the touch objects returned from touchesForView: includes all
objects associated with the specified view.
Hit-Testing
Your custom responder can use hit-testing to find the subview or sublayer of itself that is "under” a touch, and
then handle the event appropriately. It does this by either calling the hitTest:withEvent: method of
UIView or the hitTest: method of CALayer; or it can override one of these methods. Responderssometimes
perform hit-testing prior to event forwarding (see “Forwarding Touch Events” (page 35)).
Note: The hitTest:withEvent: and hitTest: methods have some slightly different behaviors.
If the point passed into hitTest:withEvent: or hitTest: is outside the bounds of the view, it is ignored.
This means that subviews that are outside their superview do not receive touch events.
If you have a custom view with subviews, you need to determine whether you want to handle touches at the
subview level or the superview level. If the subviews do not handle touches by implementing
touchesBegan:withEvent:, touchesEnded:withEvent:, or touchesMoved:withEvent:, then these
messages propagate up the responder chain to the superview. However, because multiple taps and multiple
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
33touches are associated with the subviews where they first occurred, the superview won’t receive these touches.
To ensure reception of all kinds of touches, the superview should override hitTest:withEvent: to return
itself rather than any of its subviews.
The example in Listing 2-9 detects when an “Info” image in a layer of the custom view is tapped.
Listing 2-9 Calling hitTest: on a view’s CALayer object
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint location = [[touches anyObject] locationInView:self];
CALayer *hitLayer = [[self layer] hitTest:[self convertPoint:location
fromView:nil]];
if (hitLayer == infoImage) {
[self displayInfo];
}
}
In Listing 2-10, a responder subclass (in this case, a subclass of UIWindow) overrides hitTest:withEvent:.
It first gets the hit-test view returned by the superclass. Then, if that view is itself, it substitutes the view that
is furthest down the view hierarchy.
Listing 2-10 Overriding hitTest:withEvent:
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self)
return [[self subviews] lastObject];
else
return hitView;
}
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
34Forwarding Touch Events
Event forwarding is a technique used by some applications. You forward touch events by invoking the
event-handling methods of another responder object. Although this can be an effective technique, you should
use it with caution. The classes of the UIKit framework are not designed to receive touches that are not bound
to them; in programmatic terms, this means that the view property of the UITouch object must hold a
reference to the framework object in order for the touch to be handled. If you want to conditionally forward
touches to other responders in your application, all of these responders should be instances of your own
subclasses of UIView.
For example, let’s say an application has three custom views: A, B, and C. When the user touches view A, the
application’s window determines that it is the hit-test view and sends the initial touch event to it. Depending
on certain conditions, view A forwards the event to either view B or view C. In this case, views A, B, and C must
be aware that this forwarding is going on, and views B and C must be able to deal with touches that are not
bound to them.
Event forwarding often requires analysis of touch objectsto determine where they should be forwarded. There
are several approaches you can take for this analysis:
● With an “overlay” view (such as a common superview), use hit-testing to intercept events for analysis prior
to forwarding them to subviews (see “Hit-Testing” (page 33)).
● Override sendEvent: in a custom subclass of UIWindow, analyze touches, and forward them to the
appropriate responders. In your implementation you should alwaysinvoke the superclassimplementation
of sendEvent:.
● Design your application so that touch analysis isn’t necessary
Listing 2-11 illustrates the second technique, that of overriding sendEvent: in a subclass of UIWindow. In
this example, the object to which touch events are forwarded is a custom “helper” responder that performs
affine transformations on the view that is associated with.
Listing 2-11 Forwarding touch events to “helper” responder objects
- (void)sendEvent:(UIEvent *)event
{
for (TransformGesture *gesture in transformGestures) {
// collect all the touches we care about from the event
NSSet *touches = [gesture observedTouchesForEvent:event];
NSMutableSet *began = nil;
NSMutableSet *moved = nil;
NSMutableSet *ended = nil;
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
35NSMutableSet *cancelled = nil;
// sort the touches by phase so we can handle them similarly to normal
event dispatch
for(UITouch *touch in touches) {
switch ([touch phase]) {
case UITouchPhaseBegan:
if (!began) began = [NSMutableSet set];
[began addObject:touch];
break;
case UITouchPhaseMoved:
if (!moved) moved = [NSMutableSet set];
[moved addObject:touch];
break;
case UITouchPhaseEnded:
if (!ended) ended = [NSMutableSet set];
[ended addObject:touch];
break;
case UITouchPhaseCancelled:
if (!cancelled) cancelled = [NSMutableSet set];
[cancelled addObject:touch];
break;
default:
break;
}
}
// call our methods to handle the touches
if (began) [gesture touchesBegan:began withEvent:event];
if (moved) [gesture touchesMoved:moved withEvent:event];
if (ended) [gesture touchesEnded:ended withEvent:event];
if (cancelled) [gesture touchesCancelled:cancelled withEvent:event];
}
[super sendEvent:event];
}
Multitouch Events
Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
36Notice that in this example that the overriding subclass does something important to the integrity of the
touch-event stream: It invokes the superclass implementation of sendEvent:.
Handling Events in Subclasses of UIKit Views and Controls
If you subclass a view or control class of the UIKit framework (for example, UIImageView or UISwitch) for
the purpose of altering or extending event-handling behavior, you should keep the following points in mind:
● Unlike in a custom view, it is not necessary to override each event-handling method.
● Always invoke the superclass implementation of each event-handling method that you do override.
● Do not forward events to UIKit framework objects.
Best Practices for Handling Multitouch Events
When handling events, both touch events and motion events, there are a few recommended techniques and
patterns you should follow.
● Always implement the event-cancellation methods.
In your implementation, you should restore the state of the view to what it was before the current
multitouch sequence, freeing any transient resourcesset up for handling the event. If you don’t implement
the cancellation method your view could be left in an inconsistent state. In some cases, another view
might receive the cancellation message.
●
If you handle events in a subclass of UIView, UIViewController, or (in rare cases) UIResponder,
● You should implement all of the event-handling methods (even if it is a null implementation).
● Do not call the superclass implementation of the methods.
●
If you handle events in a subclass of any other UIKit responder class,
● You do not have to implement all of the event-handling methods.
● But in the methods you do implement, be sure to call the superclass implementation. For example,
[super touchesBegan:theTouches withEvent:theEvent];
● Do not forward events to other responder objects of the UIKit framework.
The responders that you forward events to should be instances of your own subclasses of UIView, and
all of these objects must be aware that event-forwarding is taking place and that, in the case of touch
events, they may receive touches that are not bound to them.
● Custom views that redraw themselves in response to events should only set drawing state in the
event-handling methods and perform all of the drawing in the drawRect: method.
Multitouch Events
Best Practices for Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
37● Do not explicitly send events up the responder (via nextResponder); instead, invoke the superclass
implementation and let the UIKit handle responder-chain traversal.
Multitouch Events
Best Practices for Handling Multitouch Events
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
38Note: This chapter containsinformation that used to be in iPad ProgrammingGuide . The information
in this chapter has not been updated specifically for iOS 4.0.
Applicationsfor iOS are driven largely through events generated when userstouch buttons, toolbars, table-view
rows and other objects in an application’s user interface. The classes of the UIKit framework provide default
event-handling behavior for most of these objects. However, some applications, primarily those with custom
views, have to do their own event handling. They have to analyze the stream of touch objects in a multitouch
sequence and determine the intention of the user.
Most event-handling views seek to detect common gestures that users make on their surface—things such as
triple-tap, touch-and-hold (also called long press), pinching, and rotating gestures, The code for examining a
raw stream of multitouch events and detecting one or more gestures is often complex. Prior to iOS 3.2, you
cannot reuse the code except by copying it to another project and modifying it appropriately.
To help applications detect gestures, iOS 3.2 introduces gesture recognizers, objects that inherit directly from
the UIGestureRecognizer class. The following sections tell you about how these objects work, how to use
them, and how to create custom gesture recognizers that you can reuse among your applications.
Gesture Recognizers Simplify Event Handling
UIGestureRecognizer is the abstract base class for concrete gesture-recognizer subclasses (or, simply,
gesture recognizers). The UIGestureRecognizer class defines a programmatic interface and implements
the behavioral underpinnings for gesture recognition. The UIKit framework provides six gesture recognizers for
the most common gestures. For other gestures, you can design and implement your own gesture recognizer
(see “Creating Custom Gesture Recognizers” (page 50) for details).
Recognized Gestures
The UIKit framework supports the recognition of the gestures listed in Table 3-1. Each of the listed classes is a
direct subclass of UIGestureRecognizer.
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
39
Gesture RecognizersTable 3-1 Gestures recognized by the gesture-recognizer classes of the UIKit framework
Gesture UIKit class
Tapping (any number of taps) UITapGestureRecognizer
Pinching in and out (for zooming a view) UIPinchGestureRecognizer
Panning or dragging UIPanGestureRecognizer
Swiping (in any direction) UISwipeGestureRecognizer
Rotating (fingers moving in opposite directions) UIRotationGestureRecognizer
Long press (also known as “touch and hold”) UILongPressGestureRecognizer
Before you decide to use a gesture recognizer, consider how you are going to use it. Respond to gestures only
in ways that users expect. For example, a pinching gesture should scale a view, zooming it in and out; it should
not be interpreted as, say, a selection request, for which a tap is more appropriate. For guidelines about the
proper use of gestures, see iOS Human Interface Guidelines.
Gestures Recognizers Are Attached to a View
To detect its gestures, a gesture recognizer must be attached to the view that a user is touching. This view is
known as the hit-tested view. Recall that events in iOS are represented by UIEvent objects, and each event
object encapsulates the UITouch objects of the current multitouch sequence. A set of those UITouch objects
is specific to a given phase of a multitouch sequence. Delivery of events initially follows the usual path: from
operating system to the application object to the window object representing the window in which the touches
Gesture Recognizers
Gesture Recognizers Simplify Event Handling
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
40are occurring. But before sending an event to the hit-tested view, the window object sends it to the gesture
recognizer attached to that view or to any of that view’s subviews. Figure 3-1 illustrates this general path, with
the numbers indicating the order in which touches are received.
Figure 3-1 Path of touch objects when gesture recognizer is attached to a view
UIApplication
View
Gesture
Recognizer
Touch
UIWindow
1
Touch
2
Touch
3
Thus gesture recognizers act as observers of touch objects sent to their attached view or view hierarchy.
However, they are not part of that view hierarchy and do not participate in the responder chain. Gesture
recognizers may delay the delivery of touch objects to the view while they are recognizing gestures, and by
default they cancel delivery of remaining touch objects to the view once they recognize their gesture. For
more on the possible scenarios of event delivery from a gesture recognizer to its view, see “Regulating the
Delivery of Touches to Views” (page 48).
For some gestures, the locationInView: and the locationOfTouch:inView: methods of
UIGestureRecognizer enable clients to find the location of gestures or specific touches in the attached
view or its subviews. See “Responding to Gestures” (page 44) for more information.
Gestures Trigger Action Messages
When a gesture recognizer recognizes its gesture, it sends one or more action messages to one or more targets.
When you create a gesture recognizer, you initialize it with an action and a target. You may add more
target-action pairs to it thereafter. The target-action pairs are not additive; in other words, an action is only
sent to the target it was originally linked with, and not to other targets (unless they’re specified in another
target-action pair).
Discrete Gestures and Continuous Gestures
When a gesture recognizer recognizes a gesture, it sends either a single action message to its target or multiple
action messages until the gesture ends. This behavior is determined by whether the gesture is discrete or
continuous. A discrete gesture, such as a double-tap, happens just once; when a gesture recognizer recognizes
Gesture Recognizers
Gesture Recognizers Simplify Event Handling
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
41a discrete gesture, it sends its target a single action message. A continuous gesture, such as pinching, takes
place over a period and ends when the user lifts the final finger in the multitouch sequence. The gesture
recognizer sends action messages to its target at short intervals until the multitouch sequence ends.
Figure 3-2 Discrete versus continuous gestures
UITapGestureRecognizer
Tapping gesture
Pinching gesture
Touch events
Target
UIPinchGestureRecognizer Target
Action messages
Action messages
Touch events
The reference documents for the gesture-recognizer classes note whether the instances of the class detect
discrete or continuous gestures.
Implementing Gesture Recognition
To implement gesture recognition, you create a gesture-recognizer instance to which you assign a target, action,
and, in some cases, gesture-specific attributes. You attach this object to a view and then implement the action
method in your target object that handles the gesture.
Gesture Recognizers
Implementing Gesture Recognition
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
42Preparing a Gesture Recognizer
To create a gesture recognizer, you must allocate and initialize an instance of a concrete UIGestureRecognizer
subclass. When you initialize it, specify a target object and an action selector, as in the following code:
UITapGestureRecognizer *doubleFingerDTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleDoubleDoubleTap:)];
The action methods for handling gestures—and the selector for identifying them—are expected to conform
to one of two signatures:
- (void)handleGesture
- (void)handleGesture:(UIGestureRecognizer *)sender
where handleGesture and sender can be any name you choose. Methods having the second signature allow
the target to query the gesture recognizer for addition information. For example, the target of a
UIPinchGestureRecognizer object can ask that object for the current scale factor related to the pinching
gesture.
After you create a gesture recognizer, you must attach it to the view receiving touches—that is, the hit-test
view—using the UIView method addGestureRecognizer:. You can find out what gesture recognizers a
view currently has attached through the gestureRecognizers property, and you can detach a gesture
recognizer from a view by calling removeGestureRecognizer:.
The sample method in Listing 3-1 creates and initializes three gesture recognizers: a single-finger double-tap,
a panning gesture, and a rotation gesture. It then attaches each gesture-recognizer object to the same view.
For the singleFingerDTap object, the code specifies that two taps are required for the gesture to be
recognized. Each method adds the created gesture recognizer to a view and then releases it (because the view
now retains it).
Listing 3-1 Creating and initializing discrete and continuous gesture recognizers
- (void)createGestureRecognizers {
UITapGestureRecognizer *singleFingerDTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSingleDoubleTap:)];
singleFingerDTap.numberOfTapsRequired = 2;
[self.theView addGestureRecognizer:singleFingerDTap];
[singleFingerDTap release];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]
Gesture Recognizers
Implementing Gesture Recognition
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
43initWithTarget:self action:@selector(handlePanGesture:)];
[self.theView addGestureRecognizer:panGesture];
[panGesture release];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePinchGesture:)];
[self.theView addGestureRecognizer:pinchGesture];
[pinchGesture release];
}
You may also add additional targets and actions to a gesture recognizer using the addTarget:action:
method of UIGestureRecognizer. Remember that action messages for each target and action pair are
restricted to that pair; if you have multiple targets and actions, they are not additive.
Responding to Gestures
To handle a gesture, the target for the gesture recognizer must implement a method corresponding to the
action selector specified when you initialized the gesture recognizer. For discrete gestures, such as a tapping
gesture, the gesture recognizer invokesthe method once per recognition; for continuous gestures, the gesture
recognizer invokes the method at repeated intervals until the gesture ends (that is, the last finger is lifted from
the gesture recognizer’s view).
In gesture-handling methods, the target object often gets additional information about the gesture from the
gesture recognizer; it does this by obtaining the value of a property defined by the gesture recognizer, such as
scale (for scale factor) or velocity. It can also query the gesture recognizer (in appropriate cases) for the
location of the gesture.
Listing 3-2 shows handlers for two continuous gestures: a pinching gesture (handlePinchGesture:) and a
panning gesture (handlePanGesture:). It also gives an example of a handler for a discrete gesture; in this
example, when the user double-taps the view with a single finger, the handler (handleSingleDoubleTap:)
centers the view at the location of the double-tap.
Listing 3-2 Handling pinch, pan, and double-tap gestures
- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender {
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
self.view.transform = CGAffineTransformMakeScale(factor, factor);
}
Gesture Recognizers
Implementing Gesture Recognition
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
44- (IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender {
CGPoint translate = [sender translationInView:self.view];
CGRect newFrame = currentImageFrame;
newFrame.origin.x += translate.x;
newFrame.origin.y += translate.y;
sender.view.frame = newFrame;
if (sender.state == UIGestureRecognizerStateEnded)
currentImageFrame = newFrame;
}
- (IBAction)handleSingleDoubleTap:(UIGestureRecognizer *)sender {
CGPoint tapPoint = [sender locationInView:sender.view.superview];
[UIView beginAnimations:nil context:NULL];
sender.view.center = tapPoint;
[UIView commitAnimations];
}
These action methods handle the gestures in distinctive ways:
●
In the handlePinchGesture: method, the target communicates with its gesture recognizer (sender)
to get the scale factor (scale). The method uses the scale value in a Core Graphics function that scales
the view and assigns the computed value to the view’s affine transform property.
● The handlePanGesture: method applies the translationInView: values obtained from its gesture
recognizer to a cached frame value for the attached view. When the gesture concludes, it caches the
newest frame value.
●
In the handleSingleDoubleTap: method, the target gets the location of the double-tap gesture from
its gesture recognizer by calling the locationInView: method. It then uses this point, converted to
superview coordinates, to animate the center of the view to the location of the double-tap.
The scale factor obtained in the handlePinchGesture: method, as with the rotation angle and the translation
value related to other recognizers of continuous gestures, is to be applied to the state of the view when the
gesture is first recognized. It is not a delta value to be concatenated over each handler invocation for a given
gesture.
Gesture Recognizers
Implementing Gesture Recognition
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
45A hit-test with an attached gesture recognizer does not have to be passive when there are incoming touch
events. Instead, it can determine which gesture recognizers, if any, are involved with a particular UITouch
object by querying the gestureRecognizers property. Similarly, it can find out which touches a given gesture
recognizer is analyzing for a given event by calling the UIEvent method touchesForGestureRecognizer:.
Interacting with Other Gesture Recognizers
More than one gesture recognizer may be attached to a view. In the default behavior, touch events in a
multitouch sequence go from one gesture recognizer to another in a nondeterministic order until the events
are finally delivered to the view (if at all). Often this default behavior is what you want. But sometimes you
might want one or more of the following behaviors:
● Have one gesture recognizer fail before another can start analyzing touch events.
● Prevent other gesture recognizers from analyzing a specific multitouch sequence or a touch object in that
sequence.
● Permit two gesture recognizers to operate simultaneously.
The UIGestureRecognizer class provides client methods, delegate methods, and methods overridden by
subclasses to enable you to effect these behaviors.
Requiring a Gesture Recognizer to Fail
You might want a relationship between two gesture recognizers so that one can operate only if the other one
fails. For example, recognizer A doesn’t begin analyzing a multitouch sequence until recognizer B fails and,
conversely, if recognizer B does recognize its gesture, recognizer A never looks at the multitouch sequence.
An example where you might specify this relationship is when you have a gesture recognizer for a single tap
and another gesture recognizer for a double tap; the single-tap recognizer requires the double-tap recognizer
to fail before it begins operating on a multitouch sequence.
The method you call to specify this relationship is requireGestureRecognizerToFail:. After sending the
message, the receiving gesture recognizer must stay in the UIGestureRecognizerStatePossible state
until the specified gesture recognizer transitions to UIGestureRecognizerStateFailed. If the specified
gesture recognizer transitions to UIGestureRecognizerStateRecognized or
UIGestureRecognizerStateBegan instead, then the receiving recognizer can proceed, but no actionmessage
is sent if it recognizes its gesture.
Gesture Recognizers
Interacting with Other Gesture Recognizers
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
46Note: In the case of the single-tap versus double-tap gestures, if a single-tap gesture recognizer
doesn’t require the double-tap recognizer to fail, you should expect to receive yoursingle-tap actions
before your double-tap actions, even in the case of a double tap. This is expected and desirable
behavior because the best user experience generally involvesstackable actions. If you want double-tap
and single-tap gesture recognizersto have mutually exclusive actions, you can require the double-tap
recognizer to fail. You won't get any single-tap actions on a double tap, but any single-tap actions
you do receive will necessarily lag behind the user's touch input. In other words, there is no way to
know if the user double tapped until after the double-tap delay,so the single-tap gesture recognizer
cannot send its action until that delay has passed.
For a discussion of gesture-recognition states and possible transition between these states, see “State
Transitions” (page 50).
Preventing Gesture Recognizers from Analyzing Touches
You can prevent gesture recognizers from looking at specific touches or from even recognizing a gesture. You
can specify these “prevention” relationships using either delegation methods or overriding methods declared by
the UIGestureRecognizer class.
The UIGestureRecognizerDelegate protocol declares two optional methods that prevent specific gesture
recognizers from recognizing gestures on a case-by-case basis:
● gestureRecognizerShouldBegin: — This method is called when a gesture recognizer attempts to
transition out of UIGestureRecognizerStatePossible. Return NO to make it transition to
UIGestureRecognizerStateFailed instead. (The default value is YES.)
● gestureRecognizer:shouldReceiveTouch: —This method is called before the window object calls
touchesBegan:withEvent: on the gesture recognizer when there are one or more new touches. Return
NO to prevent the gesture recognizer from seeing the objects representing these touches. (The default
value is YES.)
In addition,there are two UIGestureRecognizermethods(declared in UIGestureRecognizerSubclass.h)
that effect the same behavior as these delegation methods. A subclass can override these methods to define
class-wide prevention rules:
- (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer
*)preventedGestureRecognizer;
- (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer
*)preventingGestureRecognizer;
Gesture Recognizers
Interacting with Other Gesture Recognizers
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
47Permitting Simultaneous Gesture Recognition
By default, no two gesture recognizers can attempt to recognize their gestures simultaneously. But you can
change this behavior by implementing
gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:, an optional
method of the UIGestureRecognizerDelegate protocol. This method is called when the recognition of the
receiving gesture recognizer would block the operation of the specified gesture recognizer, or vice versa.
Return YES to allow both gesture recognizers to recognize their gestures simultaneously.
Note: Returning YES is guaranteed to allow simultaneous recognition, but returning NO is not
guaranteed to prevent simultaneous recognition because the other gesture's delegate may return
YES.
Regulating the Delivery of Touches to Views
Generally, a window delivers UITouch objects (packaged in UIEvent objects) to a gesture recognizer before
it delivers them to the attached hit-test view. But there are some subtle detours and dead-ends in this general
delivery path that depend on whether a gesture is recognized. You can alter this delivery path to suit the
requirements of your application.
Default Touch-Event Delivery
By default a window in a multitouch sequence delays the delivery of touch objects in Ended phases to the
hit-test view and, if the gesture is recognized, both prevents the delivery of current touch objects to the view
and cancels touch objects previously received by the view. The exact behavior depends on the phase of touch
objects and on whether a gesture recognizer recognizes its gesture or fails to recognize it in a multitouch
sequence.
To clarify this behavior, consider a hypothetical gesture recognizer for a discrete gesture involving two touches
(that is, two fingers). Touch objects enter a system and are passed from the UIApplication object to the
UIWindow object for the hit-test view. The following sequence occurs when the gesture is recognized:
1. The window sendstwo touch objectsin the Began phase (UITouchPhaseBegan) to the gesture recognizer,
which doesn’t recognize the gesture. The window sends these same touches to the view attached to the
gesture recognizer.
2. The window sendstwo touch objectsin the Moved phase (UITouchPhaseMoved) to the gesture recognizer,
and the recognizer still doesn’t detect its gesture. The window then sends these touches to the attached
view.
Gesture Recognizers
Regulating the Delivery of Touches to Views
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
483. The window sends one touch object in the Ended phase (UITouchPhaseEnded) to the gesture recognizer.
This touch object doesn’t yield enough information for the gesture, but the window withholds the object
from the attached view.
4. The window sends the other touch object in the Ended phase. The gesture recognizer now recognizes its
gesture and so it sets its state to UIGestureRecognizerStateRecognized. Just before the first (or
only) action message issent, the view receives a touchesCancelled:withEvent: message to invalidate
the touch objects previously sent (in the Began and Moved phases). The touches in the Ended phase are
canceled.
Now assume that the gesture recognizer in the last step instead decides that this multitouch sequence it’s
been analyzing is not its gesture. It sets its state to UIGestureRecognizerStateFailed. The window then
sends the two touch objects in the Ended phase to the attached view in a touchesEnded:withEvent:
message.
A gesture recognizer for a continuous gesture goes through a similar sequence, except that it is more likely to
recognize its gesture before touch objectsreach the Ended phase. Upon recognizing its gesture, itsetsitsstate
to UIGestureRecognizerStateBegan. The window sends all subsequent touch objects in the multitouch
sequence to the gesture recognizer but not to the attached view.
Note: For a discussion of gesture-recognition states and possible transition between these states,
see “State Transitions” (page 50).
Affecting the Delivery of Touches to Views
You can change the values of three UIGestureRecognizer properties to alter the default delivery path of
touch objects to views in certain ways. These properties and their default values are:
cancelsTouchesInView (default of YES)
delaysTouchesBegan (default of NO)
delaysTouchesEnded (default of YES)
If you change the default values of these properties, you get the following differences in behavior:
● cancelsTouchesInView set to NO — Causes touchesCancelled:withEvent: to not be sent to the
view for any touches belonging to the recognized gesture. As a result, any touch objects in Began or
Moved phases previously received by the attached view are not invalidated.
● delaysTouchesBegan set to YES — Ensures that when a gesture recognizer recognizes a gesture, no
touch objects that were part of that gesture are delivered to the attached view. This setting provides a
behavior similar to that offered by the delaysContentTouches property on UIScrollView; in this
Gesture Recognizers
Regulating the Delivery of Touches to Views
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
49case, when scrolling begins soon after the touch begins, subviews of the scroll-view object never receive
the touch, so there is no flash of visual feedback. You should be careful about this setting because it can
easily make your interface feel unresponsive.
● delaysTouchesEnded set to NO — Prevents a gesture recognizer that's recognized its gesture after a
touch has ended from canceling that touch on the view. For example, say a view has a
UITapGestureRecognizer object attached with its numberOfTapsRequired set to 2, and the user
double-taps the view. If this property is set to NO, the view gets the following sequence of messages:
touchesBegan:withEvent:, touchesEnded:withEvent:, touchesBegan:withEvent:, and
touchesCancelled:withEvent:. With the property set to YES, the view gets
touchesBegan:withEvent:, touchesBegan:withEvent:, touchesCancelled:withEvent:, and
touchesCancelled:withEvent:. The purpose of this property is to ensure that a view won't complete
an action as a result of a touch that the gesture will want to cancel later.
Creating Custom Gesture Recognizers
If you are going to create a custom gesture recognizer, you need to have a clear understanding of how gesture
recognizers work. The following section gives you the architectural background of gesture recognition, and
the subsequent section goes into details of actually creating a gesture recognizer.
State Transitions
Gesture recognizers operate in a predefined state machine. They transition from one state to another depending
on whether certain conditions apply. The following enum constants from UIGestureRecognizer.h define
the states for gesture recognizers:
typedef enum {
UIGestureRecognizerStatePossible,
UIGestureRecognizerStateBegan,
UIGestureRecognizerStateChanged,
UIGestureRecognizerStateEnded,
UIGestureRecognizerStateCancelled,
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded
} UIGestureRecognizerState;
Gesture Recognizers
Creating Custom Gesture Recognizers
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
50The sequence of states that a gesture recognizer may transition through varies, depending on whether a
discrete or continuous gesture is being recognized. All gesture recognizers start in the Possible state
(UIGestureRecognizerStatePossible). They then analyze the multitouch sequence targeted at their
attached hit-test view, and they either recognize their gesture or fail to recognize it. If a gesture recognizer
does not recognize its gesture, it transitions to the Failed state(UIGestureRecognizerStateFailed); this
is true of all gesture recognizers, regardless of whether the gesture is discrete or continuous.
When a gesture is recognized, however, the state transitions differ for discrete and continuous gestures. A
recognizer for a discrete gesture transitions from Possible to Recognized
(UIGestureRecognizerStateRecognized). A recognizer for a continuous gesture, on the other hand,
transitionsfrom Possible to Began (UIGestureRecognizerStateBegan) when it first recognizesthe gesture.
Then it transitionsfrom Began to Changed (UIGestureRecognizerStateChanged), and subsequently from
Changed to Changed every time there is a change in the gesture. Finally, when the last finger in the multitouch
sequence is lifted from the hit-test view, the gesture recognizer transitions to the Ended state
(UIGestureRecognizerStateEnded), which is an aliasfor the UIGestureRecognizerStateRecognized
state. A recognizer for a continuous gesture can also transition from the Changed state to a Cancelled state
(UIGestureRecognizerStateCancelled) if it determines that the recognized gesture no longer fits the
expected pattern for its gesture. Figure 3-3 illustrates these transitions.
Figure 3-3 Possible state transitions for gesture recognizers
Possible Began Changed Cancelled
Gesture cancelled — continuous gestures
Possible Began Changed Ended
Recognizes gestures — continuous gestures
Possible Recognized
Recognizes gesture — discrete gestures
Possible Failed
Fails to recognize gesture — all gesture recognizers
Gesture Recognizers
Creating Custom Gesture Recognizers
2011-03-10 | © 2011 Apple Inc. All Rights Reserved.
51Note: The Began, Changed, Ended, and Cancelled states are not necessarily associated with UITouch
objects in corresponding touch phases. They strictly denote the phase of the gesture itself, not the
touch objects that are being recognized.
When a gesture is recognized, every subsequent state transition causes an action message to be sent to the
target. When a gesture recognizer reaches the Recognized or Ended state, it is asked to reset its internal state
in preparation for a new attempt at recognizing the gesture. The UIGestureRecognizer class then sets the
gesture recognizer’s state back to Possible.
Implementing a Custom Gesture Recognizer
To implement a custom gesture recognizer, first create a subclass of UIGestureRecognizer in Xcode. Then,
add the following import directive in your subclass’s header file:
#import
elements.
If your breaks are specifically intended as line breaks and not paragraph breaks, then you should typically use
NSLineSeparatorCharacter. Otherwise, you may use \n, \r, or \r\n depending on what other software
is likely to process your text. The default choice for Cocoa is usually \n.
Separating a String “by Paragraph”
A common approach to separating a string “by paragraph” is simply to use:
NSArray *arr = [myString componentsSeparatedByString:@"\n"];
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
28
Paragraphs and Line BreaksThis, however, ignores the fact that there are a number of other ways in which a paragraph or line break may
be represented in a string—\r, \r\n, or Unicode separators. Instead you can use methods—such as
lineRangeForRange: or getParagraphStart:end:contentsEnd:forRange:—that take into account
the variety of possible line terminations, as illustrated in the following example.
NSString *string = /* assume this exists */;
unsigned length = [string length];
unsigned paraStart = 0, paraEnd = 0, contentsEnd = 0;
NSMutableArray *array = [NSMutableArray array];
NSRange currentRange;
while (paraEnd < length) {
[string getParagraphStart:¶Start end:¶End
contentsEnd:&contentsEnd forRange:NSMakeRange(paraEnd, 0)];
currentRange = NSMakeRange(paraStart, contentsEnd - paraStart);
[array addObject:[string substringWithRange:currentRange]];
}
Paragraphs and Line Breaks
Separating a String “by Paragraph”
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
29It's common to think of a string as a sequence of characters, but when working with NSString objects, or
with Unicode strings in general, in most cases it is better to deal with substrings rather than with individual
characters. The reason for this is that what the user perceives as a character in text may in many cases be
represented by multiple characters in the string. NSString has a large inventory of methods for properly
handling Unicode strings, which in general make Unicode compliance easy, but there are a few precautions
you should observe.
NSString objects are conceptually UTF-16 with platform endianness. That doesn't necessarily imply anything
about their internalstorage mechanism; what it meansisthat NSString lengths, character indexes, and ranges
are expressed in terms of UTF-16 units, and that the term “character” in NSString method names refers to
16-bit platform-endian UTF-16 units. This is a common convention for string objects. In most cases, clients
don't need to be overly concerned with this; aslong as you are dealing with substrings, the precise interpretation
of the range indexes is not necessarily significant.
The vast majority of Unicode code points used for writing living languages are represented by single UTF-16
units. However, some less common Unicode code points are represented in UTF-16 by surrogate pairs. A
surrogate pair is a sequence of two UTF-16 units, taken from specific reserved ranges, that together represent
a single Unicode code point. CFString has functions for converting between surrogate pairs and the UTF-32
representation of the corresponding Unicode code point. When dealing with NSString objects, one constraint
is that substring boundaries usually should not separate the two halves of a surrogate pair. This is generally
automatic for rangesreturned from most Cocoa methods, but if you are constructing substring ranges yourself
you should keep this in mind. However, this is not the only constraint you should consider.
In many writing systems, a single character may be composed of a base letter plus an accent or other decoration.
The number of possible letters and accents precludes Unicode from representing each combination as a single
code point, so in general such combinations are represented by a base character followed by one or more
combining marks. For compatibility reasons, Unicode does have single code points for a number of the most
common combinations; these are referred to as precomposed forms, and Unicode normalization transformations
can be used to convert between precomposed and decomposed representations. However, even if a string is
fully precomposed, there are still many combinations that must be represented using a base character and
combining marks. For most text processing, substring ranges should be arranged so that their boundaries do
not separate a base character from its associated combining marks.
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
30
Characters and Grapheme ClustersIn addition, there are writing systems in which characters represent a combination of parts that are more
complicated than accent marks. In Korean, for example, a single Hangul syllable can be composed of two or
three subparts known as jamo. In the Indic and Indic-influenced writing systems common throughout South
and Southeast Asia, single written characters often represent combinations of consonants, vowels, and marks
such as viramas, and the Unicode representations of these writing systems often use code points for these
individual parts,so that a single character may be composed of multiple code points. For most text processing,
substring ranges should also be arranged so that their boundaries do not separate the jamo in a single Hangul
syllable, or the components of an Indic consonant cluster.
In general, these combinations—surrogate pairs, base characters plus combining marks, Hangul jamo, and
Indic consonant clusters—are referred to as grapheme clusters. In order to take them into account, you can
use NSString’s rangeOfComposedCharacterSequencesForRange: or
rangeOfComposedCharacterSequenceAtIndex: methods, or
CFStringGetRangeOfComposedCharactersAtIndex. These can be used to adjuststring indexes orsubstring
ranges so that they fall on grapheme cluster boundaries, taking into account all of the constraints mentioned
above. These methods should be the default choice for programmatically determining the boundaries of
user-perceived characters.:
In some cases, Unicode algorithms deal with multiple charactersin waysthat go beyond even grapheme cluster
boundaries. Unicode casing algorithms may convert a single character into multiple characters when going
from lowercase to uppercase; for example, the standard uppercase equivalent of the German character “ß” is
the two-letter sequence “SS”. Localized collation algorithms in many languages consider multiple-character
sequences as single units; for example, the sequence “ch” is treated as a single letter for sorting purposes in
some European languages. In order to deal properly with cases like these, it is important to use standard
NSString methods for such operations as casing, sorting, and searching, and to use them on the entire string
to which they are to apply. Use NSString methods such as lowercaseString, uppercaseString,
capitalizedString, compare: and its variants, rangeOfString: and its variants, and
rangeOfCharacterFromSet: and its variants, or their CFString equivalents. These all take into account the
complexities of Unicode string processing, and the searching and sorting methods in particular have many
options to control the types of equivalences they are to recognize.
In some less common cases, it may be necessary to tailor the definition of grapheme clusters to a particular
need. The issues involved in determining and tailoring grapheme cluster boundaries are covered in detail in
Unicode Standard Annex #29, which gives a number of examples and some algorithms. The Unicode standard
in general is the best source for information about Unicode algorithms and the considerations involved in
processing Unicode strings.
If you are interested in grapheme cluster boundaries from the point of view of cursor movement and insertion
point positioning, and you are using the Cocoa text system, you should know that on OS X v10.5 and later,
NSLayoutManager has API support for determining insertion point positions within a line of text as it is laid
Characters and Grapheme Clusters
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
31out. Note that insertion point boundaries are not identical to glyph boundaries; a ligature glyph in some cases,
such as an “fi” ligature in Latin script, may require an internal insertion point on a user-perceived character
boundary. See Cocoa Text Architecture Guide for more information.
Characters and Grapheme Clusters
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
32An NSCharacterSet object represents a set of Unicode characters. NSString and NSScanner objects use
NSCharacterSet objects to group characters together for searching operations, so that they can find any of
a particular set of characters during a search.
Character Set Basics
A character set object represents a set of Unicode characters. Character sets are represented by instances of a
class cluster. The cluster’s two public classes, NSCharacterSet and NSMutableCharacterSet, declare the
programmatic interface for immutable and mutable character sets, respectively. An immutable character set is
defined when it is created and subsequently cannot be changed. A mutable character set can be changed
after it’s created.
A character set object doesn’t perform any tasks; it simply holds a set of character values to limit operations
on strings. The NSString and NSScanner classes define methods that take NSCharacterSet objects as
argumentsto find any ofseveral characters. For example, this code excerpt findsthe range of the first uppercase
letter in myString:.
NSString *myString = @"some text in an NSString...";
NSCharacterSet *characterSet = [NSCharacterSet uppercaseLetterCharacterSet];
NSRange letterRange = [myString rangeOfCharacterFromSet:characterSet];
After this fragment executes, letterRange.location is equal to the index of the first “N” in “NSString” after
rangeOfCharacterFromSet: isinvoked. If the first letter of the string were “S”, then letterRange.location
would be 0.
Creating Character Sets
NSCharacterSet defines class methodsthat return commonly used charactersets,such asletters(uppercase
or lowercase), decimal digits, whitespace, and so on. These “standard” character sets are always immutable,
even if created by sending a message to NSMutableCharacterSet. See “Standard Character Sets and Unicode
Definitions” (page 35) for more information on standard character sets.
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
33
Character SetsYou can use a standard character set as a starting point for building a custom set by making a mutable copy
of it and changing that. (You can also start from scratch by creating a mutable character set with alloc and
init and adding characters to it.) For example, this fragment creates a character set containing letters, digits,
and basic punctuation:
NSMutableCharacterSet *workingSet = [[NSCharacterSet alphanumericCharacterSet]
mutableCopy];
[workingSet addCharactersInString:@";:,."];
NSCharacterSet *finalCharacterSet = [workingSet copy];
To define a custom character set using Unicode code points, use code similar to the following fragment (which
creates a character set including the form feed and line separator characters):
UniChar chars[] = {0x000C, 0x2028};
NSString *string = [[NSString alloc] initWithCharacters:chars
length:sizeof(chars) / sizeof(UniChar)];
NSCharacterSet *characterSet = [NSCharacterSet
characterSetWithCharactersInString:string];
Performance considerations
Because character sets often participate in performance-critical code, you should be aware of the aspects of
their use that can affect the performance of your application. Mutable character sets are generally much more
expensive than immutable character sets. They consume more memory and are costly to invert (an operation
often performed in scanning a string). Because of this, you should follow these guidelines:
● Create as few mutable character sets as possible.
● Cache character sets (in a global dictionary, perhaps) instead of continually recreating them.
● When creating a custom set that doesn’t need to change after creation, make an immutable copy of the
final character set for actual use, and dispose of the working mutable character set. Alternatively, create
a character set file as described in “Creating a character set file” (page 35) and store it in your application’s
main bundle.
● Similarly, avoid archiving characterset objects;store them in characterset filesinstead. Archiving can result
in a character set being duplicated in different archive files, resulting in wasted disk space and duplicates
in memory for each separate archive read.
Character Sets
Performance considerations
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
34Creating a character set file
If your application frequently uses a custom character set, you should save its definition in a resource file and
load that instead of explicitly adding individual characters each time you need to create the set. You can save
a character set by getting its bitmap representation (an NSData object) and saving that object to a file:
NSData *charSetRep = [finalCharacterSet bitmapRepresentation];
NSURL *dataURL = <#URL for character set#>;
NSError *error;
BOOL result = [charSetRep writeToURL:dataURL options:NSDataWritingAtomic
error:&error];
By convention, characterset filenames use the extension .bitmap. If you intend for othersto use your character
set files, you should follow this convention. To read a character set file with a .bitmap extension, simply use
the characterSetWithContentsOfFile: method.
Standard Character Sets and Unicode Definitions
The standard character sets, such as that returned by letterCharacterSet, are formally defined in terms
of the normative and informative categories established by the Unicode standard, such as Uppercase Letter,
Combining Mark, and so on. The formal definition of a standard character set is in most cases given as one or
more of the categories defined in the standard. For example, the set returned by
lowercaseLetterCharacterSet include all characters in normative category Lowercase Letters, while the
set returned by letterCharacterSet includes the characters in all of the Letter categories.
Note that the definitions of the categoriesthemselves may change with new versions of the Unicode standard.
You can download the files that define category membership from http://www.unicode.org/.
Character Sets
Creating a character set file
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
35An NSScanner object scans the characters of an NSString object, typically interpreting the characters and
converting them into number and string values. You assign the scanner’s string on creation, and the scanner
progresses through the characters of that string from beginning to end as you request items.
Creating a Scanner
NSScanner is a class cluster with a single public class, NSScanner. Generally, you instantiate a scanner object
by invoking the class method scannerWithString: or localizedScannerWithString:. Either method
returns a scanner object initialized with the string you pass to it. The newly created scanner starts at the
beginning of its string. You scan components using the scan... methods such as scanInt:, scanDouble:,
and scanString:intoString:. If you are scanning multiple lines, you typically create a while loop that
continues until the scanner is at the end of the string, as illustrated in the following code fragment:
float aFloat;
NSScanner *theScanner = [NSScanner scannerWithString:aString];
while ([theScanner isAtEnd] == NO) {
[theScanner scanFloat:&aFloat];
// implementation continues...
}
You can configure a scanner to consider or ignore case using the setCaseSensitive: method. By default
a scanner ignores case.
Using a Scanner
Scan operationsstart at the scan location and advance the scanner to just past the last character in the scanned
value representation (if any). For example, after scanning an integer from the string “137 small cases of
bananas”, a scanner’s location will be 3, indicating the space immediately after the number. Often you need
to advance the scan location to skip characters in which you are not interested. You can change the implicit
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
36
Scannersscan location with the setScanLocation: method to skip ahead a certain number of characters (you can
also use the method to rescan a portion of the string after an error). Typically, however, you either want to
skip characters from a particular character set, scan past a specific string, or scan up to a specific string.
You can configure a scanner to skip a set of characters with the setCharactersToBeSkipped: method. A
scanner ignores characters to be skipped at the beginning of any scan operation. Once it finds a scannable
character, however, it includes all characters matching the request. Scanners skip whitespace and newline
characters by default. Note that case is always considered with regard to characters to be skipped. To skip all
English vowels, for example, you must set the characters to be skipped to those in the string “AEIOUaeiou”.
If you want to read content from the current location up to a particular string, you can use
scanUpToString:intoString: (you can pass NULL as the second argument if you simply want to skip the
intervening characters). For example, given the following string:
137 small cases of bananas
you can find the type of container and number of containers using scanUpToString:intoString: asshown
in the following example.
NSString *bananas = @"137 small cases of bananas";
NSString *separatorString = @" of";
NSScanner *aScanner = [NSScanner scannerWithString:bananas];
NSInteger anInteger;
[aScanner scanInteger:&anInteger];
NSString *container;
[aScanner scanUpToString:separatorString intoString:&container];
It is important to note that the search string (separatorString) is " of". By default a scanner ignores
whitespace, so the space character after the integer is ignored. Once the scanner begins to accumulate
characters, however, all characters are added to the output string until the search string is reached. Thus if the
search string is "of" (no space before), the first value of container is “small cases ” (includes the space
following); if the search string is " of" (with a space before), the first value of container is “small cases” (no
space following).
Scanners
Using a Scanner
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
37After scanning up to a given string, the scan location is the beginning of that string. If you want to scan past
thatstring, you must therefore firstscan in the string you scanned up to. The following code fragment illustrates
how to skip past the search string in the previous example and determine the type of product in the container.
Note the use of substringFromIndex: to in effect scan up to the end of a string.
[aScanner scanString:separatorString intoString:NULL];
NSString *product;
product = [[aScanner string] substringFromIndex:[aScanner scanLocation]];
// could also use:
// product = [bananas substringFromIndex:[aScanner scanLocation]];
Example
Suppose you have a string containing lines such as:
Product: Acme Potato Peeler; Cost: 0.98 73
Product: Chef Pierre Pasta Fork; Cost: 0.75 19
Product: Chef Pierre Colander; Cost: 1.27 2
The following example uses alternating scan operationsto extract the product names and costs(costs are read
as a float forsimplicity’ssake),skipping the expected substrings“Product:” and “Cost:”, as well asthe semicolon.
Note that because a scanner skips whitespace and newlines by default, the loop does no special processing
for them (in particular there is no need to do additional whitespace processing to retrieve the final integer).
NSString *string = @"Product: Acme Potato Peeler; Cost: 0.98 73\n\
Product: Chef Pierre Pasta Fork; Cost: 0.75 19\n\
Product: Chef Pierre Colander; Cost: 1.27 2\n";
NSCharacterSet *semicolonSet;
NSScanner *theScanner;
NSString *PRODUCT = @"Product:";
NSString *COST = @"Cost:";
NSString *productName;
float productCost;
Scanners
Example
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
38NSInteger productSold;
semicolonSet = [NSCharacterSet characterSetWithCharactersInString:@";"];
theScanner = [NSScanner scannerWithString:string];
while ([theScanner isAtEnd] == NO)
{
if ([theScanner scanString:PRODUCT intoString:NULL] &&
[theScanner scanUpToCharactersFromSet:semicolonSet
intoString:&productName] &&
[theScanner scanString:@";" intoString:NULL] &&
[theScanner scanString:COST intoString:NULL] &&
[theScanner scanFloat:&productCost] &&
[theScanner scanInteger:&productSold])
{
NSLog(@"Sales of %@: $%1.2f", productName, productCost * productSold);
}
}
Localization
A scanner bases some of its scanning behavior on a locale, which specifies a language and conventions for
value representations. NSScanner uses only the locale’s definition for the decimal separator (given by the key
named NSDecimalSeparator). You can create a scanner with the user’s locale by using
localizedScannerWithString:, or set the locale explicitly using setLocale:. If you use a method that
doesn’t specify a locale, the scanner assumes the default locale values.
Scanners
Localization
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
39NSString provides a rich set of methodsfor manipulating strings asfile-system paths. You can extract a path’s
directory, filename, and extension, expand a tilde expression (such as “~me”) or create one for the user’s home
directory, and clean up paths containing symbolic links, redundant slashes, and references to “.” (current
directory) and “..” (parent directory).
Note: Where possible, you should use instances of NSURL to represent paths—the operating system
deals with URLs more efficiently than with string representations of paths.
Representing a Path
NSString represents paths generically with ‘/’ asthe path separator and ‘.’ asthe extension separator. Methods
that accept strings as path arguments convert these generic representations to the proper system-specific
form as needed. On systems with an implicit root directory, absolute paths begin with a path separator or with
a tilde expression (“~/...” or “~user/...”). Where a device must be specified, you can do that
yourself—introducing a system dependency—or allow the string object to add a default device.
You can create a standardized representation of a path using stringByStandardizingPath. This performs
a number of tasks including:
● Expansion of an initial tilde expression;
● Reduction of empty components and references to the current directory (“//” and “/./”) to single path
separators;
●
In absolute paths, resolution of references to the parent directory (“..”) to the real parent directory;
for example:
NSString *path = @"/usr/bin/./grep";
NSString *standardizedPath = [path stringByStandardizingPath];
// standardizedPath: /usr/bin/grep
path = @"~me";
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
40
String Representations of File PathsstandardizedPath = [path stringByStandardizingPath];
// standardizedPath (assuming conventional naming scheme): /Users/Me
path = @"/usr/include/objc/..";
standardizedPath = [path stringByStandardizingPath];
// standardizedPath: /usr/include
path = @"/private/usr/include";
standardizedPath = [path stringByStandardizingPath];
// standardizedPath: /usr/include
User Directories
The following examples illustrate how you can use NSString’s path utilities and other Cocoa functions to get
the user directories.
// Assuming that users’ home directories are stored in /Users
NSString *meHome = [@"~me" stringByExpandingTildeInPath];
// meHome = @"/Users/me"
NSString *mePublic = [@"~me/Public" stringByExpandingTildeInPath];
// mePublic = @"/Users/me/Public"
You can find the home directory for the current user and for a given user with NSHomeDirectory and
NSHomeDirectoryForUser respectively:
NSString *currentUserHomeDirectory = NSHomeDirectory();
NSString *meHomeDirectory = NSHomeDirectoryForUser(@"me");
Note that you should typically use the function NSSearchPathForDirectoriesInDomains to locate standard
directories for the current user. For example, instead of:
NSString *documentsDirectory =
[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
String Representations of File Paths
User Directories
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
41you should use:
NSString *documentsDirectory;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
if ([paths count] > 0) {
documentsDirectory = [paths objectAtIndex:0];
}
Path Components
NSString provides a rich set of methods for manipulating strings as file-system paths, for example:
Interprets the receiver as a path and returns the
receiver’s extension, if any.
pathExtension
Returns a new string made by deleting the
extension (if any, and only the last) from the
receiver.
stringByDeletingPathExtension
Returns a new string made by deleting the last
path component from the receiver, along with any
final path separator.
stringByDeletingLastPathComponent
Using these and related methods described in NSString Class Reference , you can extract a path’s directory,
filename, and extension, as illustrated by the following examples.
NSString *documentPath = @"~me/Public/Demo/readme.txt";
NSString *documentDirectory = [documentPath stringByDeletingLastPathComponent];
// documentDirectory = @"~me/Public/Demo"
NSString *documentFilename = [documentPath lastPathComponent];
// documentFilename = @"readme.txt"
NSString *documentExtension = [documentPath pathExtension];
// documentExtension = @"txt"
String Representations of File Paths
Path Components
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
42File Name Completion
You can find possible expansions of file names using
completePathIntoString:caseSensitive:matchesIntoArray:filterTypes:. For example, given
a directory ~/Demo that contains the following files:
ReadMe.txt readme.html readme.rtf recondite.txt test.txt
you can find all possible completions for the path ~/Demo/r as follows:
NSString *partialPath = @"~/Demo/r";
NSString *longestCompletion;
NSArray *outputArray;
unsigned allMatches = [partialPath completePathIntoString:&longestCompletion
caseSensitive:NO
matchesIntoArray:&outputArray
filterTypes:NULL];
// allMatches = 3
// longestCompletion = @"~/Demo/re"
// outputArray = (@"~/Demo/readme.html", "~/Demo/readme.rtf", "~/Demo/recondite.txt")
You can find possible completions for the path ~/Demo/r that have an extension “.txt” or “.rtf” as follows:
NSArray *filterTypes = @[@"txt", @"rtf"];
unsigned textMatches = [partialPath completePathIntoString:&outputName
caseSensitive:NO
matchesIntoArray:&outputArray
filterTypes:filterTypes];
// allMatches = 2
// longestCompletion = @"~/Demo/re"
// outputArray = (@"~/Demo/readme.rtf", @"~/Demo/recondite.txt")
String Representations of File Paths
File Name Completion
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
43You can draw string objects directly in a focused NSView using methods such as
drawAtPoint:withAttributes: (to draw a string with multiple attributes, such as multiple text fonts, you
must use an NSAttributedString object). These methods are described briefly in “Text” in Cocoa Drawing
Guide .
The simple methods, however, are designed for drawing small amounts of text or text that is only drawn
rarely—they create and dispose of various supporting objects every time you call them. To draw strings
repeatedly, it is more efficient to use NSLayoutManager, as described in “Drawing Strings”. For an overview of
the Cocoa text system, of which NSLayoutManager is a part, see Cocoa Text Architecture Guide .
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
44
Drawing StringsThis table describes the changes to String Programming Guide .
Date Notes
2012-07-17 Updated code snippets to adopt new Objective-C features.
Corrected string constant character set to UTF-8. Added guidance about
using localizedStandardCompare: for Finder-like sorting. Added caveat
to avoid using %s with RTL languages. Revised "String Format Specifiers"
article.
2012-06-11
2009-10-15 Added links to Cocoa Core Competencies.
Added new aricle on character clusters; updated list of string format
specifiers.
2008-10-15
2007-10-18 Corrected minor typographical errors.
Added notes regarding NSInteger and NSUInteger to "String Format
Specifiers".
2007-07-10
2007-03-06 Corrected minor typographical errors.
2007-02-08 Corrected sentence fragments and improved the example in "Scanners."
2006-12-05 Added code samples to illustrate searching and path manipulation.
2006-11-07 Made minor revisions to "Scanners" article.
2006-10-03 Added links to path manipulation methods.
2006-06-28 Corrected typographical errors.
Added a new article, "Reading Strings From and Writing Strings To Files
and URLs"; significantly updated "Creating and Converting Strings."
2006-05-23
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
45
Document Revision HistoryDate Notes
Included “Creating a Character Set” into “Character Sets” (page 33).
Changed title from "Strings" to conform to reference consistency
guidelines.
2006-01-10
Added “Formatting String Objects” (page 13) article. Added Data
Formatting and the Core Foundation Strings programming topics to the
introduction.
2004-06-28
Added information about custom Unicode character sets and retrieved
missing code fragments in “Creating a Character Set”. Added information
and cross-reference to “Drawing Strings” (page 44). Rewrote introduction
and added an index.
2004-02-06
Added NSNumericSearch description to “Searching, Comparing, and
Sorting Strings” (page 22).
2003-09-09
2003-03-17 Reinstated the sample code that was missing from “Scanners” (page 36).
Updated “Creating and Converting String Objects” (page 8) to
recommend the use of UTF8 encoding, and noted the pending deprecation
of the cString... methods.
2003-01-17
2002-11-12 Revision history was added to existing topic.
Document Revision History
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
46A
alloc method 34
archiving
character set objects 34
ASCII character encoding
converting string object contents 8
availableStringEncodings method 8
C
C strings
Cocoa string objects and 7
creating and converting 11
character encodings
string manipulation and 8
character sets
custom 34
example code 34
guidelines for use 34
mutable and immutable 33
saving to a file 35
standard 33, 35
characterAtIndex: method 7
characterSetWithContentsOfFile: method 35
compare: method 22
compare:options: method 22, 24
compare:options:range: method 22
comparing strings 22–23
comparison methods for strings 22
componentsSeparatedByString: method 11
current directories
resolving references to 40
D
dataUsingEncoding: method 11, 12
defaultCStringEncoding method 8
description method 13
descriptionWithLocale: method 13
directories
manipulating strings as paths 40, 42
E
encodings, character
string manipulation and 8
EUC character encoding 8
F
file-system paths and strings 42
format strings 13
G
getCharacters:length: method 12
I
init method
for mutable character sets 34
initWithData:encoding: method 8, 11, 12
initWithFormat: method 10
initWithFormat:locale: method 12
ISO Latin 1 character encoding 8
L
length method
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
47
Indexfor string objects 7
letterCharacterSet method 35
localization
scanning strings and 39
value formatting and 13
localizedScannerWithString: method 36, 39
localizedStringWithFormat: method 9, 12
lowercaseLetterCharacterSet method 35
M
myString: method 33
N
NSCharacterSet class 33
NSLayoutManager class 44
NSMutableCharacterSet class 33
NSMutableString class 7, 8
NSScanner class 23, 36–38
NSString class
creating string objects from 8
described 7
methods for representing file-system paths 40
scanners and 36
NSView class 44
P
parent directories
resolving references to 40
paths and strings 42
primitive methods
of NSString 7
printf function
NSString and 13
R
rangeOfCharacterFromSet: method 22, 33
rangeOfCharacterFromSet:options: method 22
rangeOfCharacterFromSet:options:range:
method 22
rangeOfComposedCharacterSequenceAtIndex:
method 23
rangeOfString: method 22
rangeOfString:options: method 22
rangeOfString:options:range: method 22
S
scan... methods 36
scanners 36, 38
instantiating 36
operation of 36
sample code 38
scannerWithString: method 36
scanUpToString:intoString: method 37
search methods
for strings 22
setCaseSensitive: method 36
setCharactersToBeSkipped: method 37
setLocale: method 39
setScanLocation: method 37
Shift-JIS character encoding 8
standard character sets 33, 35
string objects
combining and extracting 10
comparison methods 22
creating and converting 8–12
described 7
drawing 44
searching and comparing 22–23
stringByAppendingFormat: method 10, 12
stringByAppendingString: method 10, 12
stringWithCharacters:length: method 12
stringWithContentsOfFile: method 21
stringWithFormat: method 10
stringWithUTF8String: method 12
substringFromIndex: method 11
substringToIndex: method 11
Index
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
48substringWithRange: method 11
U
Unicode
characters in string objects 8
code points used to define character sets 34
in string objects 7
NSCharacterSet and 33
standard character sets 35
string comparison standard 22
UTF8 character encoding 11
UTF8String method 11, 12
V
value formatting
string conversion and 13
W
writeToFile:atomically: method 21
Index
2012-07-17 | © 1997, 2012 Apple Inc. All Rights Reserved.
49Apple Inc.
© 1997, 2012 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrievalsystem, or transmitted, in any
form or by any means, mechanical, electronic,
photocopying, recording, or otherwise, without
prior written permission of Apple Inc., with the
following exceptions: Any person is hereby
authorized to store documentation on a single
computer for personal use only and to print
copies of documentation for personal use
provided that the documentation contains
Apple’s copyright notice.
No licenses, express or implied, are granted with
respect to any of the technology described in this
document. Apple retains all intellectual property
rights associated with the technology described
in this document. This document is intended to
assist application developers to develop
applications only for Apple-labeled computers.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
Apple, the Apple logo, Cocoa, Finder, Mac,
Macintosh, Objective-C, OS X, and Safari are
trademarks of Apple Inc., registered in the U.S.
and other countries.
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS
DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE.ASARESULT, THISDOCUMENT IS PROVIDED
“AS IS,” AND YOU, THE READER, ARE ASSUMING THE
ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL,OR CONSEQUENTIAL
DAMAGES RESULTING FROM ANY DEFECT OR
INACCURACY IN THIS DOCUMENT, even if advised of
the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer,
agent, or employee is authorized to make any
modification, extension, or addition to this warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have other
rights which vary from state to state.
Apple AirPort Networks2
1 Contents
Chapter 1 3 Getting Started
5 Configuring an Apple Wireless Device for Internet Access Using AirPort Utility
6 Extending the Range of Your AirPort Network
6 Sharing a USB Hard Disk Connected to an AirPort Extreme Base Station or Time Capsule
6 Printing with an Apple Wireless Device
6 Sharing Your Computer’s Internet Connection
Chapter 2 9 AirPort Security
9 Security for AirPort Networks at Home
10 Security for AirPort Networks in Businesses and Classrooms
11 Wi-Fi Protected Access (WPA) and WPA2
Chapter 3 14 AirPort Network Designs
15 Using AirPort Utility
17 Setting Up the AirPort Extreme Network
24 Configuring and Sharing Internet Access
41 Setting Advanced Options
43 Extending the Range of an 802.11n Network
45 Keeping Your Network Secure
49 Directing Network Traffic to a Specific Computer on Your Network (Port Mapping)
51 Logging
52 Using Back to My Mac on your Wireless Network
53 Setting up IPv6
54 Sharing and Securing USB Hard Disks on Your Network
55 Using a Time Capsule in Your Network
55 Connecting a USB Printer to an Apple Wireless Device
56 Adding a Wireless Client to Your 802.11n Network
57 Solving Problems
Chapter 4 59 Behind the Scenes
59 Basic Networking
63 Items That Can Cause Interference with AirPort
Glossary 641
3
1 Getting Started
AirPort offers the easiest way to provide wireless Internet
access and networking anywhere in the home, classroom,
or office.
AirPort is based on the latest Institute of Electrical and Electronics Engineers (IEEE)
802.11n draft specification and provides fast and reliable wireless networking in the
home, classroom, or small office. You can enjoy data transfer rates of up to five times
faster than data rates provided by the 802.11g standard and more than twice the
network range.
The new AirPort Extreme Base Station and the new Time Capsule are based on
simultaneous dual-band technology, so they work in both the 2.4 gigahertz (GHz)
or 5 GHz spectrum at the same time. And they are 100 percent backward-compatible,
so Mac computers and PCs that use 802.11a, 802.11b, 802.11g, or IEEE draft specification
802.11n wireless cards can connect to an AirPort wireless network. They also work
flawlessly with the AirPort Express for wireless music streaming and more. The
AirPort Extreme Base Station and Time Capsule have three additional 10/100/1000BaseT Gigabit Ethernet ports, so you don’t need to include another router in your network.
To set up an AirPort Extreme Base Station, an AirPort Express, or a Time Capsule, you
use AirPort Utility, the easy-to-use setup and management application. AirPort Utility
has a simple user experience, with all software controls accessible from the same
application. It provides better management of several Apple wireless devices, with
client-monitoring features and logging.
If you’re using AirPort Utility version 5.4 or later, you can set up a guest network, in
both the 2.4 GHz and 5 GHz bands, so that guests can connect to the Internet using
your AirPort network, while you keep your private network secure. You can also choose
to set up guest accounts that expire, to grant temporary access to your network; you
no longer need to give your network password to visitors in your home or office.
You can even set up accounts with time constraints for the best in parental controls.
AirPort Utility supports IPv6 and Bonjour, so you can “advertise” network services such
as printing and sharing a hard disk over the Wide Area Network (WAN) port.4 Chapter 1 Getting Started
Note: When the features discussed in this document apply to the AirPort Extreme Base
Station, AirPort Express, and Time Capsule, the devices are referred to collectively as
Apple wireless devices.
With an AirPort Extreme Base Station or a Time Capsule, you can connect a USB hard
disk so that everyone on the network can back up, store, and share files. Every
Time Capsule includes an internal AirPort disk, so you don’t need to connect an
external one. If you want, you can connect additional USB disks to the USB port on
your Time Capsule. You can also connect a USB printer to the USB port on any
Apple wireless device, so that everyone on the network can access the printer or hub.
All Apple wireless devices provide strong, wireless security. They offer a built-in firewall
and support industry-standard encryption technologies. Yet the simple setup utility
and powerful access controls make it easy for authorized users to connect to the
AirPort network they create.
You can use an Apple wireless device to provide wireless Internet access and share a
single Internet connection among several computers in the following ways:
 Set up the device to act as a router and provide Internet Protocol (IP) addresses to
computers on the network using Dynamic Host Configuration Protocol (DHCP) and
Network Address Translation (NAT). When the wireless device is connected to a DSL
or cable modem that is connected to the Internet, it receives webpages and email
content from the Internet through its Internet connection, and then sends the
content to wireless-enabled computers, using the wireless network or using Ethernet
if there are computers connected to the Ethernet ports.
 Set up the Apple wireless device to act as a bridge on an existing network that
already has Internet access and a router providing IP addresses. The device passes
IP addresses and the Internet connection to AirPort or wireless-enabled computers,
or computers connected to the wireless device by Ethernet.
This document provides information about the latest AirPort Extreme Base Station,
AirPort Express, and Time Capsule, and detailed information about designing 802.11n
networks with AirPort Utility for computers using Mac OS X v10.5 or later, and
Windows Vista or Windows XP with Service Pack 2. If you’re using previous versions of
Mac OS X, or are setting up earlier versions of AirPort devices, you’ll find more
information at www.apple.com/support/airport.Chapter 1 Getting Started 5
You can set up an Apple wireless device and connect to the Internet wirelessly in
minutes. But because Apple wireless devices are flexible and powerful networking
products, you can also create an AirPort network that does much more. If you want to
design an AirPort network that provides Internet access to non-AirPort computers via
Ethernet, or take advantage of some of your wireless device’s more advanced features,
use this document to design and implement your network. You can find more general
wireless networking information and an overview of AirPort technology in the earlier
AirPort documents, located at www.apple.com/support/manuals/airport.
Note: The images of AirPort Utility in this document are from Mac OS X v10.5. If you’re
using a Windows computer, the images you see in this document may be slightly
different from what you see on your screen.
Configuring an Apple Wireless Device for Internet Access
Using AirPort Utility
Like your computer, Apple wireless devices must be set up with the appropriate
hardware and IP networking information to connect to the Internet. Install
AirPort Utility, which came on the CD with your wireless device, and use it to provide
Internet configuration information and other network settings.
AirPort Utility combines the ease of use of AirPort Setup Assistant and the power of
AirPort Admin Utility. It is installed in the Utilities folder in the Applications folder on
a Macintosh computer using Mac OS X, and in Start > All Programs > AirPort on
computers using Windows. AirPort Utility walks you through the setup process by
asking a series of questions to determine how the device’s Internet connection and
other interfaces should be set up. Enter the settings you received from your ISP or
network administrator for Ethernet, PPP over Ethernet (PPPoE), or your local area
network (LAN); give your AirPort network a name and password; set up a device as
a wireless bridge to extend the range of your existing AirPort network; and set other
options.
When you’ve finished entering the settings, AirPort Utility transfers the settings to your
wireless device. Then it connects to the Internet and shares its Internet connection with
computers that join its AirPort network.
You can also create an AirPort network that takes advantage of the more advanced
networking features of Apple wireless devices. To set more advanced AirPort options,
use AirPort Utility to manually set up your wireless device’s configuration, or make
quick adjustments to one you’ve already set up. Some of the AirPort advanced
networking features can be configured only using the manual setup features in
AirPort Utility. 6 Chapter 1 Getting Started
Set up your Apple wireless device manually using AirPort Utility when:
 You want to provide Internet access to computers that connect to the wireless device
using Ethernet
 you’ve already set up your device, but you need to change one setting, such as your
account information
 You need to configure advanced settings such as channel frequency, advanced
security options, closed networks, DHCP lease time, access control, WAN privacy,
power controls, or port mapping or other options
For instructions on using AirPort Utility to manually set up your wireless device and
network, see “Using AirPort Utility” on page 15.
Extending the Range of Your AirPort Network
You can extend the range of your network by using AirPort Utility to set up wireless
connections among several devices in your network, or to connect a device using
Ethernet to create a roaming network. For more information on extending the range of
your network, see “Connecting Additional Wireless Devices to Your AirPort Network” on
page 41.
Sharing a USB Hard Disk Connected to an AirPort Extreme
Base Station or Time Capsule
If you’re using an AirPort Extreme Base Station or a Time Capsule, you can connect a
USB hard disk to it, and computers connected to the network—wired or wireless, Mac
or Windows—can share files using the hard disk. Every Time Capsule includes an
internal AirPort disk, so you don’t need to connect an external one. If you want, you can
connect additional USB disks to the USB port on your Time Capsule. See “Sharing and
Securing USB Hard Disks on Your Network” on page 54.
Printing with an Apple Wireless Device
If you have a compatible USB printer connected to your Apple wireless device,
computers on the AirPort network can use Bonjour (Apple’s zero-configuration
networking technology) to print to the printer. For instructions about printing to a
USB printer from a computer, see “Connecting a USB Printer to an Apple Wireless
Device” on page 55.
Sharing Your Computer’s Internet Connection
If your computer is connected to the Internet, you can share your Internet connection
with other computers using Mac OS X version 10.2 or later, or Windows XP with Service
Pack 2. This is sometimes called using your computer as a software base station.Chapter 1 Getting Started 7
You can share your Internet connection as long as your computer is connected to the
Internet. If your computer goes to sleep or is restarted, or if you lose your Internet
connection, you need to restart Internet sharing.
To start Internet sharing on a computer using Mac OS X v10.5 or later:
1 Open System Preferences and click Sharing.
2 Choose the port you want to use to share your Internet connection from the “Share
your connection using” pop-up menu.
3 Select the port you want to use to share your Internet connection in the “To computers
using” list. You can choose to share your Internet connection with AirPort-enabled
computers or computers with built-in Ethernet, for example.
4 Select Internet Sharing in the Services list.
5 If you want to share your Internet connection with computers using AirPort, click
AirPort Options to give your network a name and password. 8 Chapter 1 Getting Started
To start Internet sharing on a computer using Windows:
1 Open Control Panel from the Start menu, and then click “Network and Internet.”
2 Click “Network and Sharing Center.”
3 Click “Manage network connections” in the Tasks list.
4 Right-click the network connection you want to share, and then select Properties.
5 Click Sharing and then select “Allow other network users to connect through this
computer’s Internet connection.”
Note: If your Internet connection and your local network use the same port (built-in
Ethernet, for example), contact your ISP before you turn on Internet sharing. In some
cases (if you use a cable modem, for example) you might unintentionally affect the
network settings of other ISP customers, and your ISP might terminate your service to
prevent you from disrupting its network.
The following chapters explain AirPort security options, AirPort network design and
setup, and other advanced options.2
9
2 AirPort Security
This chapter provides an overview of the security features
available in AirPort.
Apple has designed its wireless devices to provide several levels of security, so
you can enjoy peace of mind when you access the Internet, manage online financial
transactions, or send and receive email. The AirPort Extreme Base Station and
Time Capsule also include a slot for inserting a lock to deter theft.
For information and instructions for setting up these security features, see “Setting Up
the AirPort Extreme Network” on page 17.
Security for AirPort Networks at Home
Apple gives you ways to protect your wireless AirPort network as well as the data that
travels over it.
NAT Firewall
You can isolate your wireless network with firewall protection. Apple wireless devices
have a built-in Network Address Translation (NAT) firewall that creates a barrier
between your network and the Internet, protecting data from Internet-based IP attacks.
The firewall is automatically turned on when you set up the device to share a single
Internet connection. For computers with a cable or DSL modem, AirPort can actually be
safer than a wired connection.
Closed Network
Creating a closed network keeps the network name and the very existence of your
network private. Prospective users of your network must know the network name
and password to access it. Use AirPort Utility, located in the Utilities folder in the
Applications folder on a Macintosh computer using Mac OS X, or in Start > All
Programs > AirPort on a computer using Windows, to create a closed network.10 Chapter 2 AirPort Security
Password Protection and Encryption
AirPort uses password protection and encryption to deliver a level of security
comparable to that of traditional wired networks. Users can be required to enter a
password to log in to the AirPort network. When transmitting data and passwords,
the wireless device uses up to 128-bit encryption, through either Wi-Fi Protected Access
(WPA), WPA2, or Wired Equivalent Privacy (WEP), to scramble data and help keep
it safe. If you’re setting up an 802.11n-based AirPort device, you can also use WEP
(Transitional Security Network) if both WEP-compatible and WPA/WPA2-compatible
computers will join your network.
Note: WPA security is available only to AirPort Extreme wireless devices; AirPort and
AirPort Extreme clients using Mac OS X 10.3 or later and AirPort 3.3 or later; and to
non-Apple clients using other 802.11 wireless adapters that support WPA. WPA2
security requires firmware version 5.6 or later for an AirPort Extreme Base Station,
firmware version 6.2 or later for an AirPort Express, firmware version 7.3 or later for a
Time Capsule, and a Macintosh computer with an AirPort Extreme wireless card using
AirPort 4.2 or later. If your computer uses Windows XP or Windows Vista, check the
documentation that came with your computer to see if your computer supports WPA2.
Security for AirPort Networks in Businesses and Classrooms
Businesses and schools need to restrict network communications to authorized users
and keep data safe from prying eyes. To meet this need, Apple wireless devices and
software provide a robust suite of security mechanisms. Use AirPort Utility to set up
these advanced security features.
Transmitter Power Control
Because radio waves travel in all directions, they can extend outside the confines of a
specific building. The Transmit Power setting in AirPort Utility lets you adjust the
transmission range of your device’s network. Only users within the network vicinity
have access to the network.
MAC Address Access Control
Every AirPort and wireless card have a unique Media Access Control (MAC) address.
For AirPort Cards and AirPort Extreme Cards, the MAC address is sometimes referred to
as the AirPort ID. Support for MAC address access control lets administrators set up a
list of MAC addresses and restrict access to the network to only those users whose MAC
addresses are in the access control list.Chapter 2 AirPort Security 11
RADIUS Support
The Remote Authentication Dial-In User Service (RADIUS) makes securing a large
network easy. RADIUS is an access control protocol that allows a system administrator
to create a central list of the user names and passwords of computers that can access
the network. Placing this list on a centralized server allows many wireless devices to
access the list and makes it easy to update. If the MAC address of a user’s computer
(which is unique to each 802.11 wireless card) is not on your approved MAC address list,
the user cannot join your network.
Wi-Fi Protected Access (WPA) and WPA2
There has been increasing concern about the vulnerabilities of WEP. In response, the
Wi-Fi Alliance, in conjunction with the IEEE, has developed enhanced, interoperable
security standards called Wi-Fi Protected Access (WPA) and WPA2.
WPA and WPA2 use specifications that bring together standards-based, interoperable
security mechanisms that significantly increase the level of data protection and access
control for wireless LANs. WPA and WPA2 provide wireless LAN users with a high-level
assurance that their data remains protected and that only authorized network users
can access the network. A wireless network that uses WPA or WPA2 requires all
computers that access the wireless network to have WPA or WPA2 support. WPA
provides a high level of data protection and (when used in Enterprise mode) requires
user authentication.
The main standards-based technologies that constitute WPA include Temporal Key
Integrity Protocol (TKIP), 802.1X, Message Integrity Check (MIC), and Extensible
Authentication Protocol (EAP).
TKIP provides enhanced data encryption by addressing the WEP encryption
vulnerabilities, including the frequency with which keys are used to encrypt the
wireless connection. 802.1X and EAP provide the ability to authenticate a user on
the wireless network.
802.1X is a port-based network access control method for wired as well as wireless
networks. The IEEE adopted 802.1X as a standard in August 2001.
The Message Integrity Check (MIC) is designed to prevent an attacker from capturing
data packets, altering them, and resending them. The MIC provides a strong
mathematical function in which the receiver and the transmitter each compute and
then compare the MIC. If they do not match, the data is assumed to have been
tampered with and the packet is dropped. If multiple MIC failures occur, the network
may initiate countermeasures.12 Chapter 2 AirPort Security
The EAP protocol known as TLS (Transport Layer Security) presents a user’s information
in the form of digital certificates. A user’s digital certificates can comprise user names
and passwords, smart cards, secure IDs, or any other identity credentials that the IT
administrator is comfortable using. WPA uses a wide variety of standards-based EAP
implementations, including EAP-Transport Layer Security (EAP-TLS), EAP-Tunnel
Transport Layer Security (EAP-TTLS), and Protected Extensible Authentication Protocol
(PEAP). AirPort Extreme also supports the Lightweight Extensible Authentication
Protocol (LEAP), a security protocol used by Cisco access points to dynamically assign a
different WEP key to each user. AirPort Extreme is compatible with Cisco’s LEAP security
protocol, enabling AirPort users to join Cisco-hosted wireless networks using LEAP.
In addition to TKIP, WPA2 supports the AES-CCMP encryption protocol. Based on the
very secure AES national standard cipher, combined with sophisticated cryptographic
techniques, AES-CCMP was specifically designed for wireless networks. Migrating from
WEP to WPA2 requires new firmware for the AirPort Extreme Base Station (version 5.6 or
later), and for AirPort Express (version 6.2 or later). Devices using WPA2 mode are not
backward compatible with WEP.
WPA and WPA2 have two modes:
 Personal mode, which relies on the capabilities of TKIP or AES-CCMP without
requiring an authentication server
 Enterprise mode, which uses a separate server, such as a RADIUS server, for user
authentication
WPA and WPA2 Personal
 For home or Small Office/Home Office (SOHO) networks, WPA and WPA2 operates in
Personal mode, taking into account that the typical household or small office does
not have an authentication server. Instead of authenticating with a RADIUS server,
users manually enter a password to log in to the wireless network. When a user
enters the password correctly, the wireless device starts the encryption process using
TKIP or AES-CCMP. TKIP or AES-CCMP takes the original password and derives
encryption keys mathematically from the network password. The encryption key is
regularly changed and rotated so that the same encryption key is never used twice.
Other than entering the network password, the user isn’t required to do anything to
make WPA or WPA2 Personal work in the home.Chapter 2 AirPort Security 13
WPA and WPA2 Enterprise
WPA is a subset of the draft IEEE 802.11i standard and effectively addresses the wireless
local area network (WLAN) security requirements for the enterprise. WPA2 is a full
implementation of the ratified IEEE 802.11i standard. In an enterprise with IT resources,
WPA should be used in conjunction with an authentication server such as RADIUS to
provide centralized access control and management. With this implementation in
place, the need for add-on solutions such as virtual private networks (VPNs) may be
eliminated, at least for securing wireless connections in a network.
For more information about setting up a WPA or WPA2 protected network, see
“Using Wi-Fi Protected Access” on page 45.3
14
3 AirPort Network Designs
This chapter provides overview information and instructions
for the types of AirPort Extreme networks you can set up, and
some of the advanced options of AirPort Extreme.
Use this chapter to design and set up your AirPort Extreme network.
Configuring your Apple wireless device to implement a network design requires
three steps:
Step 1: Setting Up the AirPort Extreme Network
Computers communicate with the wireless device over the AirPort wireless network.
When you set up the AirPort network created by the wireless device, you can name the
wireless network, assign a password that will be needed to join the wireless network,
and set other options.
Step 2: Configuring and Sharing Internet Access
When computers access the Internet through the AirPort Extreme network, the wireless
device connects to the Internet and transmits information to the computers over the
AirPort Extreme network. You provide the wireless device with settings appropriate for
your ISP and configure how the device shares this connection with other computers.
Step 3: Setting Advanced Options
These settings are optional for most users. They include using the Apple wireless device
as a bridge between your AirPort Extreme network and an Ethernet network, setting
advanced security options, extending the AirPort network to other wireless devices,
and fine-tuning other settings.
For specific instructions on all these steps, refer to the sections later in this chapter.
You can do most of your setup and configuration tasks using AirPort Utility, and
following the onscreen instructions to enter your ISP and network information. To set
advanced options, you need to use AirPort Utility to manually set up your Apple
wireless device and AirPort network.Chapter 3 AirPort Network Designs 15
Using AirPort Utility
To set up and configure your computer or Apple wireless device to use AirPort Extreme
for basic wireless networking and Internet access, use AirPort Utility and answer
a series of questions about your Internet settings and how you would like to set up
your network.
1 Open AirPort Utility, located in the Utilities folder in the Applications folder on a Mac,
or in Start > All Programs > AirPort on a Windows computer.
2 Select your device in the list on the left if there is more than one device in your
network. Click Continue, and then follow the onscreen instructions to enter the settings
from your ISP or network administrator for the type of network you want to set up. See
the network diagrams later in this chapter for the types of networks you can set up
using AirPort Utility.
To set up a more complicated network, or to make adjustments to a network you’ve
already set up, use the manual setup features in AirPort Utility.
Setting AirPort preferences
Use AirPort preferences to set up your wireless device to alert you when there are
updates available for your device. You can also set it up to notify you if there are
problems detected, and to provide instructions to help solve the problems.
To set AirPort preferences:
1 Open AirPort Utility, located in the Utilities folder inside the Applications folder on
a Mac, and in Start > All Programs > AirPort on a Windows computer.
2 Do one of the following:
 On a Mac, choose AirPort Utility > Preferences
 On a Windows computer, choose File > Preferences16 Chapter 3 AirPort Network Designs
Select from the following checkboxes:
 Select “Check for Updates when opening AirPort Utility” to automatically check the
Apple website for software and firmware updates each time you open AirPort Utility.
 Select the “Check for updates” checkbox, and then choose a time interval from the
pop-up menu, such as weekly, to check for software and firmware updates in the
background. AirPort Utility opens if updates are available.
 Select “Monitor Apple wireless devices for problems” to investigate problems that
may cause the device’s status light to blink amber. With the checkbox selected,
AirPort Utility opens if a problem is detected, and then provides instructions to help
resolve the problem. This option monitors all of the wireless devices on the network.
 Select “Only Apple wireless devices that I have configured” to monitor only the
devices you’ve set up using this computer.
Monitoring devices for problems requires an AirPort wireless device that supports
firmware version 7.0 or later.
To set up your wireless device manually:
1 Open AirPort Utility, located in the Utilities folder in the Applications folder on a Mac, or
in Start > All Programs > AirPort on a Windows computer.
2 Select your device in the list.
3 Choose Base Station > Manual Setup and enter the password if necessary. The default
device password is public.
If you don’t see your wireless device in the list:
1 Open the AirPort status menu in the menu bar on a Mac and make sure that you’ve
joined the AirPort network created by your wireless device. On a Windows computer,
hover the cursor over the wireless network icon in the status tray to make sure the
computer is connected to the correct network.
The default network name for an Apple wireless device is AirPort Network XXXXXX,
where XXXXXX is replaced with the last six digits of the AirPort ID, (or MAC address).
The AirPort ID is printed on the bottom of Apple wireless devices.
2 Make sure your computer’s network and TCP/IP settings are configured properly.
On a computer using Mac OS X, choose AirPort from the Show pop-up menu in the
Network pane of System Preferences. Then choose Using DHCP from the Configure IPv4
pop-up menu in the TCP/IP pane.
On a computer using Windows, right-click the wireless connection icon that displays
the AirPort network, and choose Status. Click Properties, select Internet Protocol
(TCP/IP), and then click Properties. Make sure “Obtain an IP address automatically” is
selected.Chapter 3 AirPort Network Designs 17
If you can’t open the wireless device settings:
1 Make sure your network and TCP/IP settings are configured properly.
On a computer using Mac OS X, select AirPort from the network connection services list
in the Network pane of System Preferences. Click Advanced, and then choose Using
DHCP from the Configure IPv4 pop-up menu in the TCP/IP pane.
On a computer using Windows, right-click the wireless connection icon that displays
the AirPort network, and choose Status. Click Properties, select Internet Protocol
(TCP/IP), and then click Properties. Make sure “Obtain an IP address automatically”
is selected.
2 Make sure you entered the wireless device password correctly. The default password
is public. If you’ve forgotten the device password, you can reset it to public by resetting
the device.
To temporarily reset the device password to public, hold down the reset button for one
second. To reset the device back to its default settings, hold the reset button for five full
seconds.
If you’re on an Ethernet network that has other devices, or you’re using Ethernet to
connect to the device:
AirPort Utility scans the Ethernet network to create the list of devices. As a result, when
you open AirPort Utility, you may see devices that you cannot configure.
Setting Up the AirPort Extreme Network
The first step in configuring your Apple wireless device is setting up the device and the
network it will create. You can set up most features using AirPort Utility and following
the onscreen instructions to enter the information from your ISP or network
administrator.
To configure a network manually or set advanced options, open your wireless device’s
configuration in AirPort Utility and manually set up your device and network.
1 Choose the network of the wireless device you want to configure from the AirPort
status menu on a computer using Mac OS X, or from the wireless connection icon in
the status tray on a computer using Windows.
2 Open AirPort Utility and select the wireless device from the list. If you don’t see the
device you want to configure, click Rescan to scan for available wireless devices, and
then select the one you want from the list. 18 Chapter 3 AirPort Network Designs
3 Choose Base Station > Manual Setup and enter the password if necessary. The default
device password is public.
You can also double-click the name of the wireless device to open its configuration in
a separate window. When you open the manual setup window, the Summary pane is
displayed. The summary pane provides information and status about your wireless
device and network.Chapter 3 AirPort Network Designs 19
If the wireless device reports a problem, the status icon turns yellow. Click Base Station
Status to display the problem and suggestions to resolve it.
Wireless Device Settings
Click the AirPort button, and then click Base Station or Time Capsule, depending on the
device you’re setting up, to enter information about the wireless device.
Give the Device a Name
Give the device an easily identifiable name. This makes it easy for administrators
to locate a specific device on an Ethernet network with several devices.
Change the Device Password
The device password protects its configuration so that only the administrator can
modify it. The default password is public. It is a good idea to change the device
password to prevent unauthorized changes to it.
If the password is not changed from public, you’ll not be prompted for a password
when you select it from the list and click Configure.
Other Information
 Allow configuration over the WAN port. This allows you to administer the wireless
device remotely.
 Advertise the wireless device over the Internet using Bonjour. If you have an account
with a dynamic DNS service, you can connect to it over the Internet.
 Set the device time automatically. If you have access to a Network Time Protocol
server, whether on your network or on the Internet, choose it from the pop-up menu.
This ensures your wireless device is set to the correct time.20 Chapter 3 AirPort Network Designs
Set Device Options
Click Base Station Options and set the following:
 Enter a contact name and location for the wireless device. The name and location are
included in some logs the device generates. The contact and location fields may be
helpful if you’ve more than one wireless device on your network.
 Set status light behavior to either Always On or Flash On Activity. If you choose Flash
On Activity, the device status light blinks when there is network traffic.
 If your wireless device supports it, select “Check for firmware updates” and choose an
increment, such as Daily from the pop-up menu.
Wireless Network Settings
Click Wireless, and enter the network name, radio mode, and other wireless
information.
Setting the Wireless Mode
AirPort Extreme supports two wireless modes:
 Create a wireless network. Choose this option if you’re creating a new
AirPort Extreme network.
 Extend a wireless network. Choose this option if you plan to connect another Apple
wireless device to the network you’re setting up.
Naming the AirPort Extreme Network
Give your AirPort network a name. This name appears in the AirPort status menu on the
AirPort-enabled computers that are in range of your AirPort network.Chapter 3 AirPort Network Designs 21
Choosing the Radio Mode
Choose 802.11a/n - 802.11b/g from the Radio Mode pop-up menu if computers with
802.11a, 802.11n, 802.11g, or 802.11b wireless cards will join the network. Each client
computer will connect to the network and transmit network traffic at the highest
possible speed.
Choose 802.11n - 802.11b/g if only computers with 802.11n, 802.11b, or 802.11g
compatible wireless cards will join the network.
Note: If you don’t want to use an 802.11n radio mode, hold down the Option key and
chose a radio mode that doesn’t include 802.11n.
Changing the Channel
The “channel” is the radio frequency over which your wireless device communicates.
If you use only one device (for example, at home), you probably won’t need to change
the channel frequency. If you set up several wireless devices in a school or office,
use different channel frequencies for devices that are within approximately 150 feet of
each other.
Adjacent wireless devices should have at least 4 channels between their channel
frequencies. So if device A is set to channel 1, device B should be set to channel 6 or 11.
For best results, use channels 1, 6, or 11 when operating your device in the 2.4 GHz
range.
Choose Manually from the Radio Channel Selection pop-up menu, and then click Edit
to set the channels manually.
AirPort-enabled computers automatically tune to the channel frequency your wireless
device is using when they join the AirPort network. If you change the channel
frequency, AirPort client computers do not need to make any changes.
Password-protect Your Network
To password-protect your network, you can choose from a number of wireless security
options. In the AirPort pane of AirPort Utility, click Wireless and choose one of the
following options from the Wireless Security pop-up menu:
 None: Choosing this option turns off all password protection for the network. Any
computer with a wireless adapter or card can join the network, unless the network is
set up to use access control. See “Setting Up Access Control” on page 47.
 WEP: If your device supports it, choose this option and enter a password to protect
your network with a Wired Equivalent Privacy (WEP) password. Your Apple wireless
device supports 40-bit and 128-bit encryption. To use 40-bit WEP, don’t use an
802.11n radio mode.22 Chapter 3 AirPort Network Designs
 WPA/WPA2 Personal: Choose this option to protect your network with Wi-Fi
Protected Access. You can use a password between 8 and 63 ASCII characters or a
Pre-Shared Key of exactly 64 hexadecimal characters. Computers that support WPA
and computers that support WPA2 can join the network. Choose WPA2 Personal if
you want only computers that support WPA2 to join your network.
 WPA/WPA2 Enterprise: Choose this option if you’re setting up a network that
includes an authentication server, such as a RADIUS server, with individual user
accounts. Enter the IP address and port number for the primary and optional
secondary server, and enter a “shared secret,” which is the password for the server.
Choose WPA2 Enterprise if you want only computers that support WPA2 to join the
network.
 WEP (Transitional Security Network): If your device supports it, you can use this
option to allow computers using WPA or WPA2 to join the network. Computers or
devices that use WEP can also join the network. WEP (Transitional Security Network)
supports 128-bit encryption. To use this option, the wireless device use an 802.11n
radio mode. Hold the Option key on your keyboard while clicking the Wireless
Security pop-up menu to use WEP (Transitional Security Netowrk).
For more information and instructions for setting up WPA or WPA2 on your network,
see “Using Wi-Fi Protected Access” on page 45.
Setting Wireless Options
Click Wireless Options to set additional options for your network.Chapter 3 AirPort Network Designs 23
Setting Additional Wireless Options
Use the Wireless Options pane to set the following:
 5 GHz network name: Provide a name for the 5 GHz segment of the dual-band
network if you want it to have a different name than the 2.4 GHz network.
 Country: Choose the country for the location of your network from the Country
pop-up menu.
 Multicast rate: Choose a multicast rate from the pop-up menu. If you set the
multicast rate high, only clients on the network that are within range and can
achieve the speed you set will receive transmissions.
 Transmit power: Choose a setting from the Transmit Power pop-up menu to set the
network range (the lower the percentage, the shorter the network range).
 WPA Group Key Timeout: Enter a number in the text field, and choose an increment
from the pop-up menu to change the frequency of key rotation.
 Use Wide Channels: If you set up your network to use the 5 GHz frequency range,
you can use wide channels to provide higher network throughput.
Note: Using wide channels is not permitted in some countries.
 Create a closed network: Selecting a closed network hides the name of the
network so that users must enter the exact network name and password to join
the AirPort Extreme network.
 Use interference robustness: Interference robustness can solve interference
problems caused by other devices or networks.
To set more advanced security options, see “Keeping Your Network Secure” on page 45.24 Chapter 3 AirPort Network Designs
Setting up a Guest Network
Click Guest Network and then enter the network name and other options for the guest
network. When you set up a guest network, a portion of your connection to the
Internet is reserved for “guests”, wireless clients that can join the guest network and
connect to the Internet without accessing your private network.
Select “Allow guest network clients to communicate with each other” to allow client
computers to share files and services with each other while they’re connected to the
guest network. Make sure sharing services are set up on the client computers.
Configuring and Sharing Internet Access
The next step is setting up your wireless device’s Internet connection and sharing its
Internet access with client computers. The following sections tell you what to do,
depending on how your device connects to the Internet.
You’re Using a DSL or Cable Modem
In most cases, you can implement this network design using AirPort Utility and
following the onscreen instructions to set up your wireless device and network. You
need to use AirPort Utility to manually set up your device only if you want to set up
or adjust optional advanced settings.Chapter 3 AirPort Network Designs 25
What It Looks Like
How It Works
 The Apple wireless device (in this example, a Time Capsule) connects to the Internet
through its Internet WAN (<) connection to your DSL or cable modem.
 Computers using AirPort or computers connected to the wireless device’s Ethernet
LAN port (G) connect to the Internet through the device.
 The device is set up to use a single, public IP address to connect to the Internet, and
uses DHCP and NAT to share the Internet connection with computers on the network
using private IP addresses.
 AirPort computers and Ethernet computers communicate with one another through
the wireless device.
Important: Connect Ethernet computers that are not connected to the Internet to
the device’s LAN port (G) only. Since the device can provide network services, you
must set it up carefully to avoid interfering with other services on your Ethernet
network.
What You Need for a DSL or Cable Modem Connection
DSL or cable modem
to Internet
to Ethernet port
Time Capsule
< Ethernet WAN port
2.4 or 5 GHz
Components Check Comments
Internet account with DSL or
cable modem service provider
Does your service provider use a
static IP or DHCP configuration?
You can get this information
from your service provider or the
Network preferences pane on
the computer you use to access
the Internet through this service
provider.
Apple wireless device (an AirPort
Extreme Base Station, an AirPort
Express, or a Time Capsule)
Place the device near your DSL
or cable modem.26 Chapter 3 AirPort Network Designs
What to Do
If you’re using AirPort Utility to assist you with configuring the Apple wireless device
for Internet access:
1 Open AirPort Utility, located in the Utilities folder in the Applications folder on a Mac,
or in Start > All Programs > AirPort on a Windows computer.
2 Follow the onscreen instructions and enter the settings you received from your service
provider to connect to the Internet, and then set up the device to share the Internet
connection with computers on the network.
If you’re using AirPort Utility to manually set up your wireless device:
1 Make sure that your DSL or cable modem is connected to the Ethernet WAN port (<)
on your Apple wireless device.
2 Open AirPort Utility, located in the Utilities folder in the Applications folder on a Mac,
or in Start > All Programs > AirPort on a Windows computer. Select your wireless device
and choose Base Station > Manual Setup, or double-click your device’s icon in the list to
open the configuration in a separate window.
3 Click the Internet button. Click Internet Connection and choose Ethernet or PPPoE from
the Connect Using pop-up menu, depending on which one your service provider
requires. If your service provider gave you PPPoE connection software, such as EnterNet
or MacPoET, choose PPPoE.
Note: If you’re connecting to the Internet through a router using PPPoE and your Apple
wireless device is connected to the router via Ethernet, you do not need to use PPPoE
on your wireless device. Choose Ethernet from the Connect Using pop-up menu in the
Internet pane, and deselect the “Distribute IP addresses” checkbox in the Network
pane. Contact your service provider if you aren’t sure which one to select.
4 Choose Manually or Using DHCP from the Configure IPv4 pop-up menu if you chose
Ethernet from the Connect Using pop-up menu, depending on how your service
provider provides IP addresses.
 If your provider gave you an IP address and other numbers with your subscription,
use that information to configure the wireless device IP address manually. If you
aren’t sure, ask your service provider. Enter the IP address information in the fields
below the Configure IPv4 pop-up menu.Chapter 3 AirPort Network Designs 27
 If you chose PPPoE, your ISP provides your IP address automatically using DHCP.
If your service provider asks you for the MAC address of your wireless device, use the
address of the Ethernet WAN port (<), printed on the label on the bottom of the
device.
If you’ve already used AirPort Utility to set up your wireless device, the fields below the
Configure IPv4 pop-up menu may already contain the information appropriate for your
service provider.
You can change the WAN Ethernet speed if you have specific requirements for the
network you’re connected to. In most cases, the settings that are configured
automatically are correct. Your service provider should be able to tell you if you need
to adjust these settings.
Changing the WAN Ethernet speed can affect the way the wireless device interacts with
the Internet. Unless your service provider has given you specific settings, use the
automatic settings. Entering the wrong settings can affect network performance.
Contact your service
provider for the
information you should
enter in these fields.
Use this pop-up menu
if you need to adjust
the speed of the
Ethernet WAN port.28 Chapter 3 AirPort Network Designs
If you configure TCP/IP using DHCP, choose Using DHCP from the Configure IPv4
pop-up menu. Your IP information is provided automatically by your ISP using DHCP.
5 If you chose PPPoE from the Connect Using pop-up menu, enter the PPPoE settings
your service provider gave you. Leave the Service Name field blank unless your service
provider requires a service name.
Note: With AirPort, you don’t need to use a third-party PPPoE connection application.
You can connect to the Internet using AirPort.
Your service provider
may require you to
enter information
in these fields.
Contact your
service provider
for the information
you should enter
in these fields.Chapter 3 AirPort Network Designs 29
If you’re connecting to the Internet through a router that uses PPPoE to connect to the
Internet, and your wireless device is connected to the router via Ethernet, you do not
need to use PPPoE on your device. Choose Ethernet from the Connect Using pop-up
menu in the Internet pane, and deselect the “Distribute IP addresses” checkbox in the
Network pane. Because your router is distributing IP addresses, your wireless device
doesn’t need to. More than one device on a network providing IP addresses can cause
problems.
6 Click PPPoE to set PPPoE options for your connection.
 Choose Always On, Automatic, or Manual, depending on how you want to control
when your wireless device is connected to the Internet.
If you choose Always On, your device stays connected to your modem and the
Internet as long as the modem is turned on. If you choose Automatic, the wireless
device connects to the modem, which connects to the Internet when you use an
application that requires an Internet connection, such as email or an instant message
or web application. If you choose Manual, you need to connect the modem to the
Internet when you use an application that requires an Internet connection.
If you chose Automatic or Manual from the Connection pop-up menu, you need to
choose an increment, such as “10 minutes,” from the “Disconnect if idle” pop-up
menu. If you don’t use an Internet application after the increment of time has passed,
you’ll be disconnected from the Internet.
Note: If your wireless device is connected to your modem using an Ethernet LAN
port, and your modem is connected to the Internet using PPPoE, you may not be
able to use the manual setting.30 Chapter 3 AirPort Network Designs
 Enter Domain Name System (DNS) server addresses and a specific domain name your
wireless device accesses when you connect to the Internet.
7 Click the Network button and configure how the device will share its Internet access
with AirPort and Ethernet computers.
If you chose Ethernet from the Connect Using pop-up menu, choose how your device
will share the Internet connection from the Connection Sharing pop-up menu.
 To share a single Internet connection with AirPort computers and computers
connected to the device with Ethernet using DHCP and NAT, choose “Share a public
IP address” from the Connection Sharing pop-up menu. Using DHCP and NAT lets the
wireless device dynamically and automatically assign IP addresses to client
computers, which simplifies each computer’s TCP/IP configuration. See “Setting
DHCP and NAT Options” on page 31.
By default, the wireless device allows other devices, computers using Ethernet, and
computers using AirPort to communicate with each other using non-IP protocols like
AppleTalk. If you want to connect an AppleTalk Ethernet printer to the Apple wireless
device or use AppleTalk between wired and wireless computers, make sure the
devices are connected to the Ethernet LAN port (G) on the device.
 To distribute a range of IP addresses using only DHCP, choose “Distribute a range of
IP addresses.” See “Setting DHCP Only Options” on page 33.Chapter 3 AirPort Network Designs 31
 If you don’t want your wireless device to share its IP address, choose “Off (Bridge
Mode).” If you set up your device in bridge mode, AirPort computers have access to
all services on the Ethernet network, and the device does not provide Internet
sharing services. See “You’re Using an Existing Ethernet Network” on page 37 for
more information about setting up your wireless device as a bridge.
Using the wireless device as a bridge can be a way to address incompatibilities
between the device’s Internet sharing features and your ISP’s connection method.
Setting DHCP and NAT Options
If you chose “Share a public IP address” from the Connection Sharing pop-up menu,
you can set DHCP and NAT options. Click DHCP.
 Choose a range of IP addresses from the DHCP Range pop-up menu. Choose 10.0,
192.168, or 172.16 and then enter a beginning and ending address in the DHCP
Beginning Address and the DHCP Ending Address fields, depending on which
addresses you want the wireless device to provide.
 Enter a number in the DHCP Lease field, and then choose minutes, hours, or days
from the pop-up menu.
 Type a welcome message in the DHCP Message field. This message is displayed when
a computer joins your network.
 If your network is set up to use a Lightweight Directory Access Protocol (LDAP) server
on your network, you can enter the address of the server in the LDAP Server field,
and computers on your network will have access to it.32 Chapter 3 AirPort Network Designs
 To provide specific IP addresses to specific computers on your wireless network,
click the Add (+) button below the DHCP Reservations list, and follow the onscreen
instructions to name the reservation and reserve the address by MAC address or
DHCP client ID. If you choose MAC address, click Continue and enter the MAC
address and specific IP address.
Next you can set NAT options for the network. Click NAT.
 You can set up a default host on your network. A default host (sometimes known as
a DMZ) is a computer on your network that is exposed to the Internet and receives
all inbound traffic. A default host may be useful if you use a computer on your
AirPort network to play network games, or want to route all Internet traffic through
a single computer.
 You can set up NAT Port Mapping Protocol (NAT-PMP). NAT-PMP is an Internet
Engineering Task Force Internet Draft, an alternative to the more common Universal
Plug and Play (UPnP) protocol implemented in many network address translation
(NAT) routers. NAT-PMP allows a computer in a private network (behind a NAT router)
to automatically configure the router to allow parties outside the private network to
contact this computer.
Included in the protocol is a method for retrieving the public IP address of a NAT
gateway, allowing a client to make this public IP address and port number known to
peers that may wish to communicate with it. This protocol is implemented in current
Apple products, including Mac OS X 10.4 Tiger and later, AirPort Extreme, AirPort
Express, and Time Capsule networking products, and Bonjour for Windows.Chapter 3 AirPort Network Designs 33
You can also set up port mapping. To ensure that requests are properly routed to your
web, AppleShare, or FTP server, or a specific computer on your network, you need to
establish a permanent IP address for the server or computer, and provide “inbound port
mapping” information to the Apple wireless device. See “Directing Network Traffic to a
Specific Computer on Your Network (Port Mapping)” on page 49.
Setting DHCP Only Options
If you chose “Distribute a range of IP addresses” from the Connection Sharing pop-up
menu, your wireless device is set up to use DHCP to distribute a range of IP addresses
using only DHCP. You cannot use NAT if you chose this option. Click DHCP and enter
the beginning and ending addresses you want to distribute to computers joining your
wireless network.
You can set the additional DHCP options, such as DHCP Lease, DHCP Message, and
other options following the instructions above.
Setting Up Client Computers
To configure TCP/IP on client computers using Mac OS X v10.5:
1 Open System Preferences on the client computer and then click Network.
2 Do one of the following:
a If the client computer is using AirPort, select AirPort in the network connection
services list, and then click Advanced.34 Chapter 3 AirPort Network Designs
Next, choose DHCP from the Configure IPv4 pop-up menu.
b If you enabled a DHCP server when you set up the wireless device’s network, and the
client computer is using Ethernet, select Ethernet in the network connection services
list, and then choose Using DHCP from the Configure pop-up menu.Chapter 3 AirPort Network Designs 35
c If you selected “Distribute a range of IP addresses” when you set up the wireless
device’s network, you can provide Internet access to client computers using
Ethernet by setting the client IP addresses manually. Select Ethernet in the
network connection services list, and then choose Manually from the Configure
pop-up menu.
When you configure Ethernet clients manually for a wireless device that provides
NAT over Ethernet, you can use IP addresses in the range 10.0.1.2 to 10.0.1.200.
In the Subnet Mask field, enter 255.255.255.0. In the Router field, enter 10.0.1.1.
Enter the same name server address and search domain information that you
entered in the wireless device configuration.
To configure TCP/IP on client computers using Windows
Make sure you’ve installed the wireless adapter in your computer and the software
necessary to set up the adapter.
To configure TCP/IP on client computers:
1 Open Control Panel from the Start menu, and then click “Network and Internet.”
2 Click “Network and Sharing Center.”
3 Click “Manage network connections” in the Tasks list.
4 Right-click the wireless connection you want to share, and then select Properties.
Enter the IP and router
addresses from the range
your device is providing.
Enter the DNS and Search
Domain addresses if
necessary.36 Chapter 3 AirPort Network Designs
5 Click Internet Protocol Version 4 (TCP/IPv4), and then click Properties.
 If you chose “Share a public IP address” in the Network pane of AirPort Utility, select
“Obtain an IP address automatically.”
 If you chose “Distribute a range of IP addresses” when you set up the wireless device’s
network, you can provide Internet access to client computers by setting the client IP
addresses manually. Select “Use the following IP address.”
When you configure clients manually for a wireless device that provides NAT service,
use IP addresses in the range 10.0.1.2 to 10.0.1.200, 172.16.1.2 to 172.16.1.200, or
192.168.1.2 to 192.168.1.200.
In the “Subnet mask” field, enter 255.255.255.0. In the “Default gateway” field, enter
10.0.1.1, 172.16.1.1, or 192.168.1.1, depending on which addressing scheme you used. Enter
the same name server address and search domain information that you entered in the
wireless device configuration.Chapter 3 AirPort Network Designs 37
You’re Using an Existing Ethernet Network
You can use AirPort Utility to easily set up the Apple wireless device for Internet access
through an existing Ethernet network that already has a router, switch, or other
network device providing IP addresses. Use the manual setup features of AirPort Utility
if you need to adjust optional advanced settings.
What It Looks Like
How It Works
 The Apple wireless device (in this example, a Time Capsule) uses your Ethernet
network to communicate with the Internet through the Ethernet WAN port (<).
 AirPort and Ethernet clients access the Internet and the Ethernet network through
the Apple wireless device.
What You Need for an Ethernet Connection
Router
to Internet
to Ethernet port
Time Capsule