Last active
December 16, 2015 01:38
-
-
Save Sjors/5356176 to your computer and use it in GitHub Desktop.
Observe and notify user if app has moved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Observe and notify user if app has moved: | |
[[NSNotificationCenter defaultCenter] addObserverForName:@"AppHasMoved" | |
object:nil | |
queue:NSOperationQueuePriorityNormal | |
usingBlock:^(NSNotification *note) { | |
// Check if we've already told the user recently | |
NSDate *appHasMoved = [[NSUserDefaults standardUserDefaults] valueForKey:@"AlertAppHasMoved"]; | |
int interval = 7*24*60*60; | |
if (appHasMoved == nil || | |
[appHasMoved compare:[[NSDate date] dateByAddingTimeInterval:-interval]] == NSOrderedAscending) { | |
// Store in defaults | |
[[NSUserDefaults standardUserDefaults] setValue:[NSDate date] forKey:@"AlertAppHasMoved"]; | |
[[NSUserDefaults standardUserDefaults] synchronize]; | |
// Present popup | |
RIButtonItem *cancelItem = [RIButtonItem item]; | |
cancelItem.label = @"Later"; | |
cancelItem.action = ^{ | |
[[Mixpanel sharedInstance] track:@"Dismiss Moved App"]; | |
}; | |
RIButtonItem *downloadItem = [RIButtonItem item]; | |
downloadItem.label = @"Download"; | |
downloadItem.action = ^{ | |
[[Mixpanel sharedInstance] track:@"Download Moved App"]; | |
NSString *url = [note.userInfo valueForKey:@"new_app_location"]; | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; | |
}; | |
UIAlertView *alertView = [[UIAlertView alloc] | |
initWithTitle:[note.userInfo valueForKey:@"app_has_moved_title"] | |
message:[note.userInfo valueForKey:@"app_has_moved_message"] | |
cancelButtonItem:cancelItem | |
otherButtonItems:downloadItem, nil]; | |
[alertView show]; | |
} | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment