The document outlines topics for an advanced iOS training, including using custom delegates and protocols, saving and restoring application state, making network requests using NSURLConnection, populating data in tables, and deploying apps on devices. Key points covered are defining and conforming to protocols, preserving and restoring app state across launches, making asynchronous and synchronous network requests, and the steps required to deploy apps to physical iOS devices for testing.
2. Topics
Using custom delegate and protocols
Saving and Restoring the Application State
Introduction to NSURLConnection
Hands on example for
Fetching data from server
Using Table View Controller
Populating Data in a Table
Refreshing Data
Deploying your app on a device
Yahoo! Confidential
2
3. Using custom delegate and protocols
Defining Protocol
@protocol DataConsumerDelegate
// Method to handle response of the rest connection call
- (void) finishedReceivingData: (NSData *) data;
@end
Conforming to protocol
@interface MyDataConsumer : NSObject <DataConsumerDelegate>
@end
@implementation MyDataConsumer
- (void) finishedReceivingData: (NSData *) data {
// HANDLE THE DATA
}
@end
Yahoo! Confidential
3
4. Using custom delegate and protocols
Using delegate
@interface AsynchronousRestConnection : NSObject {
id<DataConsumerDelegate> dataConsumerDelegate;
}
// Used to store delgate object (it must conform to DataConsumerDelegateprotocol)
@property (nonatomic, weak) id<DataConsumerDelegate> dataConsumerDelegate;
- (void) getData;
@end
@implementation AsynchronousRestConnection
@synthesize dataConsumerDelegate;
- (void) getData {
// GET DATA AND STORE IT IN data
// YOU CAN DO MULTI QUERY AND MERGE OUTPUT
[self.dataConsumerDelegate finishedReceivingData:data];
}
@end
Yahoo! Confidential
4
5. Using custom delegate and protocols
Updating the MyDataConsumer class to use AsynchronousRestConnection
@interface MyDataConsumer : NSObject <DataConsumerDelegate>
- (void) getDataFromApi;
@end
@implementation MyDataConsumer
- (void) finishedReceivingData: (NSData *) data {
// HANDLE THE DATA
}
- (void) getDataFromApi {
AsynchronousRestConnection *arc = [[AsynchronousRestConnection alloc] init];
arc.dataConsumerDelegate = self;
// CONSUME DATA
}
@end
Yahoo! Confidential
5
6. Topics
Using custom delegate and protocols
Saving and Restoring the Application State
Introduction to NSURLConnection
Hands on example for
Fetching data from server
Using Table View Controller
Populating Data in a Table
Refreshing Data
Deploying your app on a device
Yahoo! Confidential
6
7. Saving and Restoring Application State
During the preservation and restoration process, your app has a handful of
responsibilities.
During preservation, your app is responsible for:
Telling UIKit that it supports state preservation.
Telling UIKit which view controllers and views should be preserved.
Encoding relevant data for any preserved objects.
During restoration, your app is responsible for:
Telling UIKit that it supports state restoration.
Providing (or creating) the objects that are requested by UIKit.
Decoding the state of your preserved objects and using it to return the
object to its previous state.
Yahoo! Confidential
7
8. Saving and Restoring Application State
High-level flow interface preservation
Yahoo! Confidential
8
9. Saving and Restoring Application State
High-level flow for restoring your user interface
Yahoo! Confidential
9
10. Topics
Using custom delegate and protocols
Saving and Restoring the Application State
Introduction to NSURLConnection
Hands on example for
Fetching data from server
Using Table View Controller
Populating Data in a Table
Refreshing Data
Deploying your app on a device
Yahoo! Confidential
10
11. Introduction to NSURLConnection
Asynchronous Request
Synchronous Request
POST request
Using Connection Timeout
Cache Policies
Yahoo! Confidential
11
12. Asynchronous Request
To fetch some data, we’ll follow these 3 basic steps:
Have our class conform to the NSURLConnectionDelegate protocol and
declare a var to store the response data
Implement the NSURLConnectionDelegate protocol methods
Create an instance of NSURLRequest and NSURLConnection to kick off
the request
Yahoo! Confidential
12
16. Asynchronous Request
Step 4:
First connection:didReceiveResponse will be hit, indicating that the server
has responded.
Then the handler, connection:didReceiveData: will be hit several times.
This is where you’ll append the latest data to the response data variable
you declared in Step 1.
Then finally, connectionDidFinishLoading: will be hit and you can parse
the response data variable.
Yahoo! Confidential
16
17. POST Request
A synchronous request looks like the below:
You’ll set the HTTPMethod property to POST
You’ll assign the header fields and value in the body
Ensure that you’re using an instance of NSMutableURLRequest because
NSURLRequest is immutable.
Yahoo! Confidential
17
18. Using Connection Timeout
Using Connection Timeout
If you want to set a timeout for your data retrieval, you can set the timeoutInterval
property of your NSURLRequest.
Ensure that you’re using an instance of NSMutableURLRequest because
NSURLRequest is immutable.
Yahoo! Confidential
18
19. Cache Policies
To specify how your data should be cached locally, you can set a cache
policy with your NSURLRequest.
Following snippet shows you how you can define a cache policy and a
timeout.
If you don’t specify any caching policy with your NSURLRequest, then it
will try to conform to whatever the protocol states.
For example, with HTTP it will look at the server response headers and try
to conform to what it dictates about caching.
Yahoo! Confidential
19
20. Topics
Using custom delegate and protocols
Saving and Restoring the Application State
Introduction to NSURLConnection
Hands on example for
Fetching data from server
Using Table View Controller
Populating Data in a Table
Refreshing Data
Deploying your app on a device
Yahoo! Confidential
20
21. Topics
Using custom delegate and protocols
Saving and Restoring the Application State
Introduction to NSURLConnection
Hands on example for
Fetching data from server
Using Table View Controller
Populating Data in a Table
Refreshing Data
Deploying your app on a device
Yahoo! Confidential
21
22. Deploying your app on a device
Steps to deploy your app on a device
Step 1: iOS Developer Program (iPhone provision portal)
Step 2: Create a Certificate Signing Request
Step 3: Create a Development Certificate
Step 4: Adding a Device
Step 5: Create an App ID
Step 6: Create a Provisioning Profile
Step 7: Configuring the Project
Step 8: Build and Run
For detail refer:
http://mobile.tutsplus.com/tutorials/iphone/how-to-test-your-apps-on-physical-iosdevices/
Yahoo! Confidential
22
Hinweis der Redaktion
Another Reference:http://www.raywenderlich.com/8003/how-to-submit-your-app-to-apple-from-no-account-to-app-store-part-1