Skip to content

Instantly share code, notes, and snippets.

@qmihara
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qmihara/8f39025e9857b498047f to your computer and use it in GitHub Desktop.
Save qmihara/8f39025e9857b498047f to your computer and use it in GitHub Desktop.
#import <Parse/Parse.h>
#import "AppDelegate.h"
static NSString * const kParseApplicationID = @"";
static NSString * const kParseClientKey = @"";
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Parse setApplicationId:kParseApplicationID clientKey:kParseClientKey];
[[UIApplication sharedApplication] registerForRemoteNotifications];
UIMutableUserNotificationAction *acceptAction = [UIMutableUserNotificationAction new];
acceptAction .identifier = @"ACCEPT_IDENTIFIER";
acceptAction .title = @"Accept";
acceptAction .activationMode = UIUserNotificationActivationModeBackground;
acceptAction .destructive = NO;
acceptAction .authenticationRequired = NO;
UIMutableUserNotificationAction *maybeAction = [UIMutableUserNotificationAction new];
maybeAction .identifier = @"MAYBE_IDENTIFIER";
maybeAction .title = @"Maybe";
maybeAction .activationMode = UIUserNotificationActivationModeBackground;
maybeAction .destructive = NO;
maybeAction .authenticationRequired = NO;
UIMutableUserNotificationAction *declineAction = [UIMutableUserNotificationAction new];
declineAction .identifier = @"DECLINE_IDENTIFIER";
declineAction .title = @"Decline";
declineAction .activationMode = UIUserNotificationActivationModeBackground;
declineAction .destructive = YES;
declineAction .authenticationRequired = NO;
UIMutableUserNotificationCategory *inviteCategory = [UIMutableUserNotificationCategory new];
inviteCategory.identifier = @"INVITE_CATEGORY";
[inviteCategory setActions:@[acceptAction, maybeAction, declineAction] forContext:UIUserNotificationActionContextDefault];
[inviteCategory setActions:@[acceptAction, declineAction] forContext:UIUserNotificationActionContextMinimal];
NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
UILocalNotification *localNotification = [UILocalNotification new];
localNotification.alertBody = @"Local notification";
localNotification.category = @"INVITE_CATEGORY";
[application scheduleLocalNotification:localNotification];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken:%@", deviceToken);
PFInstallation *installation = [PFInstallation currentInstallation];
[installation setDeviceTokenFromData:deviceToken];
[installation saveInBackground];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"didFailToRegisterForRemoteNotificationsWithError:%@", error);
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
NSLog(@"notificationSettings:%@", notificationSettings);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"application:%@ didReceiveRemoteNotification:%@ fetchCompletionHandler:%@", application, userInfo, completionHandler);
if (completionHandler) {
completionHandler(UIBackgroundFetchResultNoData);
}
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler {
NSLog(@"identifier:%@ userInfo:%@ completionHandler:%@", identifier, userInfo, completionHandler);
if ([identifier isEqualToString:@"ACCEPT_IDENTIFIER"]) {
// ...
} else if ([identifier isEqualToString:@"MAYBE_IDENTIFIER"]) {
// ...
}
if (completionHandler) {
completionHandler();
}
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler {
NSLog(@"identifier:%@ notification:%@ completionHandler:%@", identifier, notification, completionHandler);
if ([identifier isEqualToString:@"ACCEPT_IDENTIFIER"]) {
// ...
} else if ([identifier isEqualToString:@"MAYBE_IDENTIFIER"]) {
// ...
}
if (completionHandler) {
completionHandler();
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment