nymea-app/packaging/ios/pushnotifications.mm

49 lines
2.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#import "UIKit/UIKit.h"
// Include our C++ class
#include "pushnotifications.h"
// This is hidden, so we declare it here to hook into it
@interface QIOSApplicationDelegate
@end
//add a category to QIOSApplicationDelegate
@interface QIOSApplicationDelegate (APNSApplicationDelegate)
// No need to declare the methods here, since were overriding existing ones
@end
@implementation QIOSApplicationDelegate (APNSApplicationDelegate)
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register to receive notifications from the system
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[application registerForRemoteNotifications];
NSLog(@"registered for remote notifications");
return YES;
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken);
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
// [deviceToken description] is like "{length = 32, bytes = 0xd3d997af 967d1f43 b405374a 13394d2f ... 28f10282 14af515f }"
NSString *token = [self hexadecimalStringFromData:deviceToken];
#else
// [deviceToken description] is like "<124686a5 556a72ca d808f572 00c323b9 3eff9285 92445590 3225757d b83967be>"
NSString *token = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:@"<" withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString:@" " withString:@""];
#endif
PushNotifications::instance()->setAPNSRegistrationToken(QString::fromNSString(token));
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Did Fail to Register for Remote Notifications");
NSLog(@"%@, %@", error, error.localizedDescription);
}
@end