[cocoaheads tricity] michał tuszyński - modern ios apps

24
Modern iOS app Architecture Michał Tuszyński iOS Developer, Schibsted Tech Polska

Upload: cocoaheads-tricity

Post on 15-Aug-2015

55 views

Category:

Software


0 download

TRANSCRIPT

Page 1: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Modern iOS app Architecture

Michał TuszyńskiiOS Developer, Schibsted Tech Polska

Page 2: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Agenda

1. Real time apps2. Modern asynchronous Core Data3. Embedded frameworks

Page 3: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

Page 4: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

func startPolling() { let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update:", userInfo: nil, repeats: true) NSRunLoop.currentRunLoop().addTimer(timer, forMode: NSDefaultRunLoopMode) } @objc func update(timer: NSTimer) { let request = NSURLRequest(URL: NSURL(string: "https://myawsomeapp.com/get_something")!) let task = session.dataTaskWithRequest(request, completionHandler: handler) task.resume() }

Page 5: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

Continuous polling is (usually) bad.

Page 6: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

Alternative?

Page 7: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

Silent Notifications!

Page 8: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

{ "aps": { "content-available": 1, "sound": "" }, "object": { "value": "test" } }

Silent Notifications!

Page 9: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void)

Silent Notifications!

Page 10: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Background fetch

Silent Notifications!

Page 11: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Background fetch

func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

Page 12: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Realtime app demohttp://pushtest.srgtuszy.com

Page 13: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

let context = NSManagedObjectContext() context.persistentStoreCoordinator = persistentStore

Page 14: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

Thread confinement is obsolete and left for backwards compatibility

Page 15: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

What’s wrong?

Parent-child contexts are the way to go

Page 16: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Asynchronous Core Data?

Page 17: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Asynchronous Core Data?

- Separate context for writing to persistent store- NSAsynchronousFetchRequest- NSBatchUpdateFetchRequest

Page 18: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Embedded Frameworks

Page 19: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Frameworks vs static libraries

Page 20: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Choosing the right option

Page 21: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Use dlopen() on iOS 7

Page 22: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

if (SystemVersionGreaterOrEqual(@"8.0")) { NSString *frameworkPath = [[NSBundle mainBundle] pathForResource:@"HockeySDK" ofType:@"framework"]; NSString *libraryPath = [frameworkPath stringByAppendingPathComponent:@"HockeySDK"]; void *handle = dlopen([libraryPath cStringUsingEncoding:NSUTF8StringEncoding], RTLD_LAZY); if (handle == NULL) { NSString *error = [NSString stringWithUTF8String:dlerror()]; NSLog(@"dlopen failed: %@", error); return; } id hockeyManager = [[NSClassFromString(@"BITAuthenticator") alloc] init]; dlclose(handle); }

Page 23: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Wrap up

Page 24: [CocoaHeads Tricity] Michał Tuszyński - Modern iOS Apps

Thank you!