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

Post on 15-Aug-2015

55 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Modern iOS app Architecture

Michał TuszyńskiiOS Developer, Schibsted Tech Polska

Agenda

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

What’s wrong?

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() }

What’s wrong?

Continuous polling is (usually) bad.

What’s wrong?

Alternative?

What’s wrong?

Silent Notifications!

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

Silent Notifications!

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

Silent Notifications!

Background fetch

Silent Notifications!

Background fetch

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

Realtime app demohttp://pushtest.srgtuszy.com

What’s wrong?

let context = NSManagedObjectContext() context.persistentStoreCoordinator = persistentStore

What’s wrong?

Thread confinement is obsolete and left for backwards compatibility

What’s wrong?

Parent-child contexts are the way to go

Asynchronous Core Data?

Asynchronous Core Data?

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

Embedded Frameworks

Frameworks vs static libraries

Choosing the right option

Use dlopen() on iOS 7

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); }

Wrap up

Thank you!

top related