You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/03/17 10:36:34 UTC
cordova-plugins git commit: CB-8475 - Initial commit of
notification-rebroadcast plugin. Untested.
Repository: cordova-plugins
Updated Branches:
refs/heads/master 1e1f519c3 -> 784430c6b
CB-8475 - Initial commit of notification-rebroadcast plugin. Untested.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/784430c6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/784430c6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/784430c6
Branch: refs/heads/master
Commit: 784430c6b1fd479bd747d4938bd0c12689fb4d5a
Parents: 1e1f519
Author: Shazron Abdullah <sh...@apache.org>
Authored: Tue Mar 17 02:36:32 2015 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue Mar 17 02:36:32 2015 -0700
----------------------------------------------------------------------
notification-rebroadcast/README.md | 23 ++++++
notification-rebroadcast/plugin.xml | 32 ++++++++
.../src/ios/CDVNotificationRebroadcast.h | 34 ++++++++
.../src/ios/CDVNotificationRebroadcast.m | 85 ++++++++++++++++++++
4 files changed, 174 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/784430c6/notification-rebroadcast/README.md
----------------------------------------------------------------------
diff --git a/notification-rebroadcast/README.md b/notification-rebroadcast/README.md
new file mode 100644
index 0000000..7d94246
--- /dev/null
+++ b/notification-rebroadcast/README.md
@@ -0,0 +1,23 @@
+Cordova Notification Rebroadcast Plugin
+======
+
+See [CB-8475](https://issues.apache.org/jira/browse/CB-8475). This plugin rebroadcasts remote push notifications as well as local notifications to other plugins.
+
+Install:
+
+ cordova plugin add https://github.com/apache/cordova-plugins.git#master:notification-rebroadcast
+
+Permissions
+-----------
+
+#### config.xml
+
+ <feature name="CDVNotificationRebroadcast">
+ <param name="ios-package" value="CDVNotificationRebroadcast" />
+ <param name="onload" value="true" />
+ </feature>
+
+Supported Platforms
+-------------------
+
+- iOS
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/784430c6/notification-rebroadcast/plugin.xml
----------------------------------------------------------------------
diff --git a/notification-rebroadcast/plugin.xml b/notification-rebroadcast/plugin.xml
new file mode 100644
index 0000000..388efee
--- /dev/null
+++ b/notification-rebroadcast/plugin.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+ xmlns:rim="http://www.blackberry.com/ns/widgets"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ id="org.apache.cordova.labs.notification-rebroadcast"
+ version="0.1.0">
+ <name>Cordova Notification Rebroadcast Plugin</name>
+ <description>rebroadcasts local and remote notifications to other plugins, and as events in JavaScript</description>
+ <license>Apache 2.0</license>
+ <keywords>cordova,local,remote,push,notifications</keywords>
+ <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugins.git</repo>
+
+ <engines>
+ <engine name="cordova" version=">=3.9.9" />
+ </engines>
+
+ <!-- ios -->
+ <platform name="ios">
+ <config-file target="config.xml" parent="/*">
+ <feature name="CDVNotificationRebroadcast">
+ <param name="ios-package" value="CDVNotificationRebroadcast" />
+ <param name="onload" value="true" />
+ </feature>
+ </config-file>
+
+ <header-file src="src/ios/CDVNotificationRebroadcast.h" />
+ <source-file src="src/ios/CDVNotificationRebroadcast.m" />
+
+ </platform>
+
+</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/784430c6/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.h
----------------------------------------------------------------------
diff --git a/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.h b/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.h
new file mode 100644
index 0000000..2cc27be
--- /dev/null
+++ b/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.h
@@ -0,0 +1,34 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Cordova/CDV.h>
+
+@interface CDVAppDelegate (SwizzledMethods)
+
+- (void) customApplication:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification;
+
+- (void) customApplication:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;
+
+- (void) customApplication:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error;
+
+@end
+
+@interface CDVNotificationRebroadcast : CDVPlugin
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/784430c6/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.m
----------------------------------------------------------------------
diff --git a/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.m b/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.m
new file mode 100644
index 0000000..f064151
--- /dev/null
+++ b/notification-rebroadcast/src/ios/CDVNotificationRebroadcast.m
@@ -0,0 +1,85 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVNotificationRebroadcast.h"
+#import <objc/runtime.h>
+
+@implementation CDVAppDelegate (SwizzledMethods)
+
++ (void)load
+{
+ Method original, custom;
+
+ original = class_getInstanceMethod(self, @selector(application:didReceiveLocalNotification:));
+ custom = class_getInstanceMethod(self, @selector(customApplication:didReceiveLocalNotification:));
+ method_exchangeImplementations(original, custom);
+
+ original = class_getInstanceMethod(self, @selector(application:didRegisterForRemoteNotificationsWithDeviceToken:));
+ custom = class_getInstanceMethod(self, @selector(customApplication:didRegisterForRemoteNotificationsWithDeviceToken:));
+ method_exchangeImplementations(original, custom);
+
+ original = class_getInstanceMethod(self, @selector(application:didFailToRegisterForRemoteNotificationsWithError:));
+ custom = class_getInstanceMethod(self, @selector(customApplication:didFailToRegisterForRemoteNotificationsWithError:));
+ method_exchangeImplementations(original, custom);
+}
+
+- (void) customApplication:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification
+{
+ // re-post ( broadcast )
+ [[NSNotificationCenter defaultCenter] postNotificationName:CDVLocalNotification object:notification];
+
+ // no, not recursion. we swapped implementations, remember. calling original implementation
+ [self customApplication:application didReceiveLocalNotification:notification];
+}
+
+- (void) customApplication:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken;
+{
+ // re-post ( broadcast )
+ NSString* token = [[[[deviceToken description]
+ stringByReplacingOccurrencesOfString:@"<" withString:@""]
+ stringByReplacingOccurrencesOfString:@">" withString:@""]
+ stringByReplacingOccurrencesOfString:@" " withString:@""];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
+
+ // no, not recursion. we swapped implementations, remember. calling original implementation
+ [self customApplication:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+}
+
+- (void) customApplication:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error;
+{
+ // re-post ( broadcast )
+ [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
+
+ // no, not recursion. we swapped implementations, remember. calling original implementation
+ [self customApplication:application didFailToRegisterForRemoteNotificationsWithError:error];
+}
+
+
+@end
+
+@implementation CDVNotificationRebroadcast : CDVPlugin
+
+
+- (void)pluginInitialize
+{
+ // TODO: listen to the notifications, and send to JavaScript as events?
+}
+
+@end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org