Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions WordPress/Classes/NotificationsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ + (void)registrationDidFail:(NSError *)error {
}

+ (void)unregisterDeviceToken {
[[UIApplication sharedApplication] unregisterForRemoteNotifications];

NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:NotificationsDeviceToken];
if (nil == token) {
return;
Expand Down Expand Up @@ -93,7 +95,7 @@ + (void)unregisterDeviceToken {

#pragma mark - Notification handling

+ (void)handleNotification:(NSDictionary*)userInfo forState:(UIApplicationState)state completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
+ (void)handleNotification:(NSDictionary *)userInfo forState:(UIApplicationState)state completionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
DDLogInfo(@"Received push notification:\nPayload: %@\nCurrent Application state: %d", userInfo, state);

switch (state) {
Expand All @@ -108,9 +110,6 @@ + (void)handleNotification:(NSDictionary*)userInfo forState:(UIApplicationState)
break;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astralbodies - Did you mean to get rid of the mixpanel call as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it since this is fired off and has no user interaction (app didn't actually open)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh - can we move it to someplace where the user does have interaction - i.e. https://github.com/wordpress-mobile/WordPress-iOS/pull/1000/files#diff-12c33a973ac67adb445a57af0d26b92cR128?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sendhil It is being handled in this method - sorry it took me forever to verify 😄

+ (void)handleNotificationForApplicationLaunch:(NSDictionary *)launchOptions {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astralbodies - awesome, thanks for that.

case UIApplicationStateBackground:
[WPMobileStats recordAppOpenedForEvent:StatsEventAppOpenedDueToPushNotification];
[[WordPressAppDelegate sharedWordPressApplicationDelegate] showNotificationsTab];

if (completionHandler) {
[Note getNewNotificationswithContext:[[ContextManager sharedInstance] mainContext] success:^(BOOL hasNewNotes) {
DDLogInfo(@"notification fetch completion handler completed with new notes: %@", hasNewNotes ? @"YES" : @"NO");
Expand Down
53 changes: 31 additions & 22 deletions WordPress/Classes/WordPressAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ - (void)dealloc {
#pragma mark - UIApplicationDelegate

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[WordPressAppDelegate fixKeychainAccess];

// Crash reporting, logging, debugging
[self configureLogging];
[self configureHockeySDK];
[self configureCrashlytics];
[self printDebugLaunchInfo];
[self printDebugLaunchInfoWithLaunchOptions:launchOptions];
[self toggleExtraDebuggingIfNeeded];
[self removeCredentialsForDebug];

Expand All @@ -106,33 +108,41 @@ - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:

[self customizeAppearance];

CGRect bounds = [[UIScreen mainScreen] bounds];
[self.window setFrame:bounds];
[self.window setBounds:bounds]; // for good measure.

self.window.backgroundColor = [UIColor blackColor];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

[self showWelcomeScreenIfNeededAnimated:NO];

// Push notifications
[NotificationsManager registerForPushNotifications];
[NotificationsManager handleNotificationForApplicationLaunch:launchOptions];

// Deferred tasks to speed up app launch
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[self changeCurrentDirectory];
[WordPressAppDelegate fixKeychainAccess];
[[PocketAPI sharedAPI] setConsumerKey:[WordPressComApiCredentials pocketConsumerKey]];
[self cleanUnusedMediaFileFromTmpDir];
});

return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
DDLogVerbose(@"didFinishLaunchingWithOptions state: %d", application.applicationState);

// Launched by tapping a notification
if (application.applicationState == UIApplicationStateActive) {
[NotificationsManager handleNotificationForApplicationLaunch:launchOptions];
}

CGRect bounds = [[UIScreen mainScreen] bounds];
[self.window setFrame:bounds];
[self.window setBounds:bounds]; // for good measure.

self.window.backgroundColor = [UIColor blackColor];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];

[self showWelcomeScreenIfNeededAnimated:NO];

return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
BOOL returnValue = NO;

if ([[BITHockeyManager sharedHockeyManager].authenticator handleOpenURL:url
Expand Down Expand Up @@ -238,8 +248,8 @@ - (void)applicationDidEnterBackground:(UIApplication *)application {
}];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
- (void)applicationWillEnterForeground:(UIApplication *)application {
DDLogInfo(@"%@ %@", self, NSStringFromSelector(_cmd));
[WPMobileStats resumeSession];
}

Expand All @@ -257,13 +267,11 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {
[[WordPressComApi sharedApi] syncPushNotificationInfo];
}

- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder
{
- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder {
return YES;
}

- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder
{
- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder {
return YES;
}

Expand Down Expand Up @@ -924,7 +932,7 @@ + (void)fixKeychainAccess

#pragma mark - Debugging and logging

- (void)printDebugLaunchInfo {
- (void)printDebugLaunchInfoWithLaunchOptions:(NSDictionary *)launchOptions {
UIDevice *device = [UIDevice currentDevice];
NSInteger crashCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"crashCount"];
NSArray *languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
Expand All @@ -945,6 +953,7 @@ - (void)printDebugLaunchInfo {
DDLogInfo(@"Language: %@", currentLanguage);
DDLogInfo(@"UDID: %@", [device wordpressIdentifier]);
DDLogInfo(@"APN token: %@", [[NSUserDefaults standardUserDefaults] objectForKey:NotificationsDeviceToken]);
DDLogInfo(@"Launch options: %@", launchOptions);
DDLogInfo(@"===========================================================================");
}

Expand Down