1. Trang chủ
  2. » Công Nghệ Thông Tin

iPhone SDK Programming A Beginner’s Guide phần 3 ppsx

48 302 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Chapter 5: Deploying to an iPhone, Debugging, and Testing 81 After registering your devices, you can obtain application IDs and provision them. Any application you wish to test on a device must have an App ID (Figure 5-3). After obtaining the App ID, you must obtain a provisioning profile (Figure 5-4). A provisioning profile is installed on your device. An application is tied to a provisioning profile, so, a provisioning profile allows you to install a particular application on a particular device. Apple’s Developer Portal has a complete discussion of the provisioning process; the process is not difficult. What I did when learning the process was open two browser windows, one where I muddled through the steps and one where I skimmed the instructions. It helped that I have two monitors. In the following example, I take you through registering and installing a simple application on my iPhone. Figure 5-2 The Devices tab 82 iPhone SDK Programming: A Beginner’s Guide Figure 5-3 The App IDs tab Chapter 5: Deploying to an iPhone, Debugging, and Testing 83 Try This Deploying an Application to iPhone 1. Create a new View-based Application named OnMyPhone. 2. Log in to the iPhone Developer Program Portal. 3. Click the Certificates tab. If you haven’t installed your certificate, do so now. These steps assume a certificate (see Figure 5-2). 4. Click the Devices tab. If you haven’t installed your devices, do so now. These steps assume a registered device (see Figure 5-3). Figure 5-4 The Provisioning Profile tab (continued) 84 iPhone SDK Programming: A Beginner’s Guide 5. Click the App IDs tab and add the application (see Figure 5-3). Click the Add ID button on the page’s right, and add the OnMyPhone application (Figure 5-5). 6. Click the Provisioning tab and click the Add Profile button on the page’s right (see Figure 5-4). Complete the form; be certain you select the certificate and the device you want to provision (Figure 5-6). 7. Click Submit, and you return to the Provisioning page. The Provisioning Profile’s status for My On My Phone Profile should say “Pending.” Refresh the page until the status has an “Active until” date. You are usually quickly granted a profile. 8. Download the profile by clicking the Download button next to the profile. The profile should have a title like “My_On_My_Phone_Profile.mobileprovision.” Move it to a safe location. Figure 5-5 Adding an application to the App IDs Chapter 5: Deploying to an iPhone, Debugging, and Testing 85 9. Ensure your device is connected to your computer. 10. Return to Xcode. From the Windows menu, select Organizer. If your device is attached, it should appear under DEVICES (Figure 5-7). 11. Drag the provision file to the Provisioning list. 12. Change the application’s Active SDK to Device – 3.0 | Debug. NOTE Select the latest SDK on your computer, not necessarily 3.0. Figure 5-6 Provisioning the OnMyPhone application (continued) 86 iPhone SDK Programming: A Beginner’s Guide 13. You might receive an error the first time (Figure 5-8). Don’t despair; the error is often easily fixed. 14. Open the project’s Project Info window and navigate to the Build tab. Change the code signing identity to the provision just installed (Figure 5-9). 15. Close the Project Info window and open Info.plist. Change the bundle identifier to OnMyPhone. 16. Click Build And Go, and the application installs and runs on your device. You should see logging in the Debugger Console similar to Listing 5-1. Figure 5-7 The Organizer window Chapter 5: Deploying to an iPhone, Debugging, and Testing 87 Figure 5-8 Error message Figure 5-9 Changing the code signing identity (continued) 88 iPhone SDK Programming: A Beginner’s Guide Listing 5-1 Debugger Console logging when running on iPhone Program loaded. target remote-mobile /tmp/.XcodeGDBRemote-1193-51 Switching to remote protocol mem 0x1000 0x3fffffff cache mem 0x40000000 0xffffffff none mem 0x00000000 0x0fff none sharedlibrary apply-load-rules all run Running… NOTE For more information on provisioning, obtaining App IDs, and other program portal topics, refer to Apple’s “iPhone Developer Program User Guide.” Debugging Debugging and testing your application is paramount if you wish to provide users with a robust application. Xcode provides several excellent tools for debugging and testing your applications. In this section, you explore basic debugging using Xcode’s graphical front-end to the GNU debugger. NOTE For a more complete introduction to debugging, refer to Apple’s “Xcode Debugging Guide,” available online. Using the Debugger Xcode’s visual debugger overlays the command-line GNU debugger. The open-source GNU debugger has a long pedigree and is the industry standard when it comes to C and C++ debuggers on UNIX and Linux. Figure 5-10 shows the debugger window’s panes. The top left pane is the Thread list, also sometimes called the call stack. This tells you where your application is currently at in any point in the application’s processing. Below the stack pane is the Text editor pane. The right pane is the Variable list. This pane lets you see the current function’s local variable values, argument values, and constant variables. Along the debugger window’s top, notice the Build And Go, Tasks, Restart, Continue, Step Over, Step Into, Step Out, and Deactivate buttons. Also notice the Breakpoints and Console buttons to the right of the other buttons. Table 5-1 summarizes each button’s purpose. Chapter 5: Deploying to an iPhone, Debugging, and Testing 89 Figure 5-10 The debugger window Button Function Build And Go Builds the application and launches it in the debugger. Tasks Stops any tasks currently running. Restart Stops and starts the application running in the debugger. Pause/Continue Pauses the application running in the debugger. Note, when the application is paused, this button says Continue. Continue “un-pauses” the application and resumes processing. Step Over Processes the next line of code. If the next line is a function call, it skips over the function, proceeding to the next line. Step Into Processes the next line of code. If the line is a function call, it jumps to the code in the function. Step Out Processes until the function exits. Deactivate Disables the current breakpoint. Breakpoints Opens the Breakpoints window. Console Opens the Debugger Console window. Table 5-1 Debugger Window Buttons 90 iPhone SDK Programming: A Beginner’s Guide Breakpoints Breakpoints tell the debugger where to pause. If you set no breakpoints and then run the application in the debugger, nothing unusual happens, as you didn’t tell the application to pause. There are several ways to set a breakpoint, but the easiest is to click in the Editor window’s gutter next to the line of code you wish the debugger to stop at (Figure 5-11). If you wish to disable the breakpoint, click it again and it turns light blue, indicating it is disabled. If you wish to remove the breakpoint, ctrl-click and select Remove Breakpoint from the pop-up menu. Alternatively, you can drag the breakpoint off the gutter to remove it. When you run the application in the debugger, it will pause processing at the first encountered breakpoint. Stepping Through Code When an application pauses at a breakpoint, you can step through your code’s execution. Step Over moves directly to the next line, skipping over any functions. Step Into also moves to the next line, but if the next line is a function, it jumps to the function’s first line, and you can Figure 5-11 Setting a breakpoint [...]... UIApplicationDelegate 109 110 iPhone SDK Programming: A Beginner’s Guide Key Skills & Concepts ● Understanding the UIApplication class ● Understanding the UIApplicationDelegate protocol ● Handling application startup and termination ● Handling application interruptions E very iPhone application has one UIApplication UIApplication is an iPhone application’s starting point and is responsible for initializing and displaying... alloc] init]; NSMutableArray * myArray = [[NSMutableArray alloc] initWithObjects: myFooBar,nil]; [myFooBar dealloc]; [[myArray objectAtIndex:0] sayHello]; FooBar is allocated, initialized, and added to myArray There are two references to myFooBar, so its retainCount is two However, deallocating myFooBar makes both references invalid, pointing to deallocated memory space The sayHello message is sent to... displaying your application’s UIWindow It is also responsible for loading your application’s first UIView into the UIWindow Another responsibility UIApplication has is managing your application’s life cycle UIApplication fulfils this management responsibility using a delegate called UIApplicationDelegate Although UIApplication receives events, it’s the UIApplicationDelegate that handles how an application... Click Leaks, and a detailed list of the leaked objects appears Click one of the leaks 8 Click View | Extended Detail, and a call stack appears on the window’s right (Figure 5- 23) 9 Double-click the viewDidAppear call, and the debugger opens to the line allocating and initializing FooBar Figure 5-22 The Leaks panel Chapter 5: Figure 5- 23 Deploying to an iPhone, Debugging, and Testing The Leaks panel showing... appears with the variable and its value (Figure 5-12) You can even modify the value if desired Figure 5-12 The Debugger datatips 91 92 iPhone SDK Programming: A Beginner’s Guide Figure 5- 13 Setting a watchpoint Watchpoints Sometimes you might be interested in having the program pause when a value changes A watchpoint pauses the program when the watched item’s value changes Setting a watchpoint is tricky... the Arguments tab and add the NSZombieEnabled variable to the variable list Assign it the value YES and ensure it is selected 8 Build and debug Now the error message is more descriptive (Listing 5-6) Listing 5-6 Debugger Console output after zombies are enabled Attaching to program: `/Users/jamesbrannan/Library/Application Support /iPhone Simulator/User/Applications/F 834 0D01-C5D8-45AF-9 6A4 512660FD 238 0/Zombie.app/Zombie',... *)application { FooBar * myFooBar = [[FooBar alloc] init]; Chapter 5: Deploying to an iPhone, Debugging, and Testing NSMutableArray * myArray = [[NSMutableArray alloc] initWithObjects:myFooBar,nil]; [myFooBar dealloc]; [[myArray objectAtIndex:0] sayHello]; [window addSubview:viewController.view]; [window makeKeyAndVisible]; } - (void)dealloc { [viewController release]; [window release]; [super dealloc];... enabled Attaching to program: `/Users/jamesbrannan/Library/Application Support /iPhone Simulator/User/Applications/05688B 53- AF22-4F21 -95D3AFFE268 2A6 EA/Zombie.app/Zombie', process 135 1 objc[ 135 1]: FREED(id): message sayHello sent to freed object=0x521bd0 Program received signal: "EXC_BAD_INSTRUCTION" 6 In the Groups & Files pane, expand Executables and double-click Zombies This should open the Executable... the UIApplicationDelegate might handle include application life cycle events, such as startup and shutdown, and system events like incoming phone calls and calendar alerts In this chapter, after learning how to load an application’s root view into the UIWindow, you explore handling system events using the UIApplicationDelegate protocol Try This Adding a UIView and UIViewController to a UIApplicationDelegate... limited Also ensure your application runs quickly and is responsive Carefully debugging and testing your application can often be the difference between “yet another widget app” and the “best widget app” on the App Store Chances are your application is not going to be the first of anything anymore, so try making it the best 107 This page intentionally left blank Chapter 6 UIApplication and UIApplicationDelegate . output after zombies are enabled Attaching to program: `/Users/jamesbrannan/Library/Application Support /iPhone Simulator/User/Applications/F 834 0D01-C5D8-45AF-9 6A4 - 512660FD 238 0/Zombie.app/Zombie',. fragment is obviously an error. FooBar * myFooBar = [[FooBar alloc] init]; NSMutableArray * myArray = [[NSMutableArray alloc] initWithObjects: myFooBar,nil]; [myFooBar dealloc]; [[myArray. a datatip appears with the variable and its value (Figure 5-12). You can even modify the value if desired. Figure 5-12 The Debugger datatips 92 iPhone SDK Programming: A Beginner’s Guide Watchpoints Sometimes

Ngày đăng: 13/08/2014, 18:20

Xem thêm: iPhone SDK Programming A Beginner’s Guide phần 3 ppsx

TỪ KHÓA LIÊN QUAN

Mục lục

    5 Deploying to an iPhone, Debugging, and Testing

    Try This: Deploying an Application to iPhone

    Try This: Debugging an Application

    Try This: Enabling Zombies

    Try This: Find a Memory Leak

    Find a Memory Leak on iPhone Simulator

    Deploying and Distributing Your Application

    Try This: Adding a UIView and UIViewController to a UIApplicationDelegate

    Connecting UIWindow, UIApplication, and UIApplicationDelegate

    Handling Application Life Cycle Events

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN