AppDelegate.m revision e89f4330a4e6e51eb675c5644317545156125894
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the Common Development and
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Distribution License (the License). You may not use this file except in compliance with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * specific language governing permission and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Software, include this CDDL Header Notice in each file and include
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Header, with the fields enclosed by brackets [] replaced by your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: "Portions copyright [year] [name of copyright owner]".
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright 2016 ForgeRock AS.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Portions Copyright 2013 Nathaniel McCallum, Red Hat
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#import "AppDelegate.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#import "FRAApplicationAssembly.h"
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright#import "FRAError.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#import "FRAIdentity.h"
c586600796766c83eb9485c446886fd9ed2359a9Keyur Desai#import "FRAIdentityDatabase.h"
68b2bbf26c7040fea4281dcb58b81e7627e46f34Gordon Ross#import "FRAIdentityModel.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#import "FRAMechanismReaderAction.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#import "FRAUriMechanismReader.h"
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#import "FRANotification.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#import "FRANotificationGateway.h"
3db3f65c6274eb042354801a308c8e9bc4994553amw#import "FRAOathMechanism.h"
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#import "FRAPushMechanism.h"
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross@implementation AppDelegate
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma mark -
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma mark UIApplicationDelegate - application lifecycle state changes
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NSLog(@"application:willFinishLaunchingWithOptions:%@", launchOptions);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return YES;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
b1352070d318187b41b088da3533692976f3f225Alan Wright- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [[[self assembly] notificationGateway] application:application didFinishLaunchingWithOptions:launchOptions];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleIdentityDatabaseChanged:) name:FRAIdentityDatabaseChangedNotification object:nil];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [self updateNotificationsCount];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NSLog(@"application:didFinishLaunchingWithOptions\n%@", launchOptions);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return YES;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States- (void)applicationWillTerminate:(UIApplication *)application {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States NSLog(@"applicationWillTerminate:");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States [[NSNotificationCenter defaultCenter] removeObserver:self];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
7b59d02d2a384be9a08087b14defadd214b3c1ddjb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb#pragma mark -
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb#pragma mark UIApplicationDelegate - handling remote notifications
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb NSLog(@"application:didRegisterForRemoteNotificationsWithDeviceToken:");
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb [[[self assembly] notificationGateway] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError:");
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb [[[self assembly] notificationGateway] application:application didFailToRegisterForRemoteNotificationsWithError:error];
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NSLog(@"application:didReceiveRemoteNotification:");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [[[self assembly] notificationGateway] application:application didReceiveRemoteNotification:userInfo];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NSLog(@"application:didReceiveRemoteNotification:fetchCompletionHandler:");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [[[self assembly] notificationGateway] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma mark -
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#pragma mark UIApplicationDelegate - opening a URL-specified resource
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross NSLog(@"application:openURL:sourceApplication:annotation:");
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross // Create mechanism from URL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw @autoreleasepool {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NSError *error;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw FRAMechanismReaderAction *mechanismReaderAction = [[self assembly] mechanismReaderAction];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw BOOL result = [mechanismReaderAction read:url.absoluteString error:&error];
7b59d02d2a384be9a08087b14defadd214b3c1ddjb if (result) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb // Reload the view
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [self.window.rootViewController loadView];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return result;
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as }
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma mark -
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#pragma mark AppDelegate (private)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw- (id)initialFactory {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw TyphoonComponentFactory *factory = [[TyphoonBlockComponentFactory alloc] initWithAssembly:[FRAApplicationAssembly assembly]];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [factory makeDefault];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return factory;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb- (FRAApplicationAssembly *)assembly {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (FRAApplicationAssembly *) [TyphoonComponentFactory defaultFactory];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw- (void)handleIdentityDatabaseChanged:(NSNotification *)notification {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw NSLog(@"database changed: %@", notification.userInfo);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [self updateNotificationsCount];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross- (void)updateNotificationsCount {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw [UIApplication sharedApplication].applicationIconBadgeNumber = [[[self assembly] identityModel] pendingNotificationsCount];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb@end
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw