2. URL SESSION
• New in iOS 7 and OS X 10.9
• Preferred API for (up/down-)loading URL contents
• Many use case scenarios. Get URL contents as NSData or file,
background download/upload, cookie/cache/authentication
handling, etc.
• This talk is about background downloads only
• You should check AFNetworking 2.0.Was just released!
3. URL SESSION
• URL Session types: Default, Ephemeral, Background
• App initiates a download (in process)
• iOS handles it for you (out of process)
• Apps gets notified/restarted when finished
4. URL SESSION
• What happens when:
- App is iOS-terminated in the background? Download continues.
- Rebooting the phone? Download continues.
- App killed by user? Download is aborted.
• And when download finishes?
- Your app is restarted (if not running) to handle it.
9. TIPS &TRICKS
• Download tasks cannot use completion handler for background
session.Why? Because app process can be killed at any time! Use
delegate methods.
• You should immediately copy the downloaded file somewhere.
• You need to identify the finished download. Parse the URL? No.
There’s a better (& well hidden) solution:
• If your app is restarted, you can delay the call to the OS-passed
completion handler until you have finished processing.
[NSURLProtocol setProperty:voiceKey forKey:@"voiceKey" inRequest:request];
11. MOTION EFFECTS
• Parallax: Objects move at
different speed depending on
their distance to viewer
• iOS does not track your eyes,
but gyroscope provides a good
approximation of relative
viewer position.
• With that information, you can
simulate the parallax effect by
moving contents
A
B
12. MOTION EFFECTS
• UIMotionEffect, that you can subclass
@interface CRParallaxMotionEffect : UIMotionEffect
- (NSDictionary *)keyPathsAndRelativeValuesForViewerOffset:(UIOffset)viewerOffset
{
! return @{@”center”: [NSValue valueWithCGPoint:
CGPointMake(viewerOffset.horizontal*10, viewerOffset.vertical*10)]};
}
[view addMotionEffect:parallaxEffect];
14. TIPS &TRICKS
• We used the first approach, add effect with single line of code
• CRParallaxMotionEffect available on GitHub: http://bit.ly/prllx
[view addMotionEffect:[CRParallaxMotionEffect parallaxEffectWithAmplitude:10.0]];
15. TIPS &TRICKS
• Make moving views bigger!
• For scrollviews, use ‘contentOffset’, but with motion in the
opposite direction (negate amplitude)
• Not only points, but also colors, shadow offset, layer
properties, 2D and 3D transforms.
view.frame = CGRectInset(container.bounds, -10.0, -10.0);