Skip to content

Instantly share code, notes, and snippets.

@tschubotz
Last active August 29, 2015 14:07
Show Gist options
  • Save tschubotz/d7a3b3e267ccac6a6a92 to your computer and use it in GitHub Desktop.
Save tschubotz/d7a3b3e267ccac6a6a92 to your computer and use it in GitHub Desktop.
//
// AAAppDelegate.m
#import "AAAppDelegate.h"
#import <Pushwoosh/PushNotificationManager.h>
@interface MMAppDelegate ()
@end
@implementation MMAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Pushwoosh
NSString* pushwooshAppCode;
pushwooshAppCode = @"...";
[PushNotificationManager initializeWithAppCode:pushwooshAppCode appName:@"..."];
// set custom delegate for push handling
[PushNotificationManager pushManager].delegate = self;
// handling push on app start
[[PushNotificationManager pushManager] handlePushReceived:launchOptions];
// make sure we count app open in Pushwoosh stats
[[PushNotificationManager pushManager] sendAppOpen];
// don't show push notifications when app is open
[PushNotificationManager pushManager].showPushnotificationAlert = NO;
[[PushNotificationManager pushManager] registerForPushNotifications];
return YES;
}
#pragma mark -
#pragma mark Push notifications
#pragma mark -
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
{
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
{
// Pushwoosh
[[PushNotificationManager pushManager] handlePushRegistration:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
{
// Pushwoosh
[[PushNotificationManager pushManager] handlePushRegistrationFailure:error];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
{
// Pushwoosh
[[PushNotificationManager pushManager] handlePushReceived:userInfo];
}
#pragma mark -
#pragma mark Pushwoosh
#pragma mark -
- (void) onPushAccepted:(PushNotificationManager *)pushManager withNotification:(NSDictionary *)pushNotification onStart:(BOOL)onStart {
// do nothing when application was already active
if (!onStart) {
return;
}
if (pushNotification[@"u"]) {
NSData *pushData = [pushNotification[@"u"] dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *pushInformation = [NSJSONSerialization JSONObjectWithData: pushData options:NSJSONReadingMutableContainers error:nil];
//work with information
}
// reset batch number to 0
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
@end
@shaders
Copy link

shaders commented Oct 27, 2014

You don't need this line:

    - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
    {
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment