tailieunhanh - iOS App Programming Guide phần 10

Nếu ứng dụng của bạn vẫn hoạt động nhưng ở chế độ nền hoặc bị đình chỉ khi một yêu cầu URL, nó được chuyển sang tiền cảnh để mở các URL. Ngay sau đó, hệ thống các cuộc gọi của đại biểu ứng dụng: OpenURL sourceApplication: chú thích: để kiểm tra các URL và mở nó. | CHAPTER 6 Advanced App Tricks Figure 6-2 Launching an app to open a URL Switch to a different app If your app is running but is in the background or suspended when a URL request arrives it is moved to the foreground to open the URL. Shortly thereafter the system calls the delegate s app1ication openURL sourceApp1ication annotation to check the URL and open it. If your delegate does not implement this method or the current system version is iOS or earlier the system calls your delegate s application handleOpenURL method instead. Figure 6-3 shows the modified process for moving an app to the foreground to open a URL. Implementing Custom URL Schemes 2011-10-12 2011 Apple Inc. All Rights Reserved. 101 CHAPTER 6 Advanced App Tricks Figure 6-3 Waking a background app to open a URL URL arrives 1_T Note Apps that support custom URL schemes can specify different launch images to be displayed when launching the app to handle a URL. For more information about how to specify these launch images see Providing Launch Images for Custom URL Schemes page 85 . All URLs are passed to your app in an NSURL object. It is up to you to define the format of the URL but the NSURL class conforms to the RFC 1808 specification and therefore supports most URL formatting conventions. Specifically the class includes methods that return the various parts of a URL as defined by RFC 1808 including the user password query fragment and parameter strings. The protocol for your custom scheme can use these URL parts for conveying various kinds of information. In the implementation of application handleOpenURL shown in Listing 6-1 the passed-in URL object conveys app-specific information in its query and fragment parts. The delegate extracts this information in this case the name of a to-do task and the date the task is due and with it creates a model object of the app. This example assumes that the user is using a Gregorian calendar. If your app supports non-Gregorian calendars you need to design .