Skip to content

Instantly share code, notes, and snippets.

@Sjors
Last active December 16, 2015 01:38
Show Gist options
  • Save Sjors/5356176 to your computer and use it in GitHub Desktop.
Save Sjors/5356176 to your computer and use it in GitHub Desktop.
Observe and notify user if app has moved
// 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