-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from JoaoCaixinha/master
Adds push notifications support to RCTRealtimeMessaging
- Loading branch information
Showing
10 changed files
with
223 additions
and
181 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
RCTRealtimeMessaging/AppDelegate+RealtimeRCTPushNotifications.h
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// AppDelegate+RealtimeRCTPushNotifications.h | ||
// RCTRealtimeMessaging | ||
// | ||
// Created by Joao Caixinha on 07/09/15. | ||
// Copyright (c) 2015 Realtime. All rights reserved. | ||
// | ||
#import "AppDelegate.h" | ||
|
||
|
||
@interface AppDelegate (RealtimeRCTPushNotifications) | ||
|
||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken; | ||
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error; | ||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo; | ||
|
||
@end |
81 changes: 81 additions & 0 deletions
81
RCTRealtimeMessaging/AppDelegate+RealtimeRCTPushNotifications.m
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// AppDelegate+RealtimeRCTPushNotifications.m | ||
// RCTRealtimeMessaging | ||
// | ||
// Created by Joao Caixinha on 07/09/15. | ||
// Copyright (c) 2015 Realtime. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate+RealtimeRCTPushNotifications.h" | ||
#import <objc/runtime.h> | ||
|
||
#pragma GCC diagnostic ignored "-Wundeclared-selector" | ||
@implementation AppDelegate (RealtimeRCTPushNotifications) | ||
|
||
|
||
+ (void)load | ||
{ | ||
[[NSNotificationCenter defaultCenter] addObserver:[self class] selector:@selector(registForNotifications) name:UIApplicationDidFinishLaunchingNotification object:nil]; | ||
} | ||
|
||
|
||
+ (BOOL)registForNotifications | ||
{ | ||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 | ||
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { | ||
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; | ||
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; | ||
[[UIApplication sharedApplication] registerForRemoteNotifications]; | ||
} else { | ||
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge]; | ||
} | ||
#else | ||
[application registerForRemoteNotificationTypes: UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge]; | ||
#endif | ||
|
||
return YES; | ||
} | ||
|
||
|
||
|
||
- (void)application:(UIApplication *)application | ||
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken | ||
{ | ||
NSString* newToken = [deviceToken description]; | ||
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; | ||
newToken = [newToken stringByReplacingOccurrencesOfString:@" " withString:@""]; | ||
NSLog(@"\n\n - didRegisterForRemoteNotificationsWithDeviceToken:\n%@\n", deviceToken); | ||
|
||
id ortc = NSClassFromString (@"OrtcClient"); | ||
if ([ortc respondsToSelector:@selector(setDEVICE_TOKEN:)]) { | ||
[ortc performSelector:@selector(setDEVICE_TOKEN:) withObject:[[NSString alloc] initWithString:newToken]]; | ||
} | ||
} | ||
|
||
|
||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler | ||
{ | ||
[self application:application didReceiveRemoteNotification:userInfo]; | ||
completionHandler(UIBackgroundFetchResultNewData); | ||
} | ||
|
||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo | ||
{ | ||
if ([userInfo objectForKey:@"C"] && [userInfo objectForKey:@"M"] && [userInfo objectForKey:@"A"]) { | ||
[[NSNotificationCenter defaultCenter] postNotificationName:@"ApnsNotification" object:nil userInfo:userInfo]; | ||
} | ||
} | ||
|
||
|
||
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error | ||
{ | ||
NSLog(@"Failed to register with error : %@", error); | ||
|
||
[[NSNotificationCenter defaultCenter] postNotificationName:@"ApnsRegisterError" object:nil userInfo:[NSDictionary dictionaryWithObject:error forKey:@"ApnsRegisterError"]]; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
@end |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.