diff --git a/README.md b/README.md
index 150f884..7361d8b 100644
--- a/README.md
+++ b/README.md
@@ -13,43 +13,6 @@ Add the plugin much like any other:
`cordova plugin add com.rd11.remote-controls`
-#### Modify the MainViewController.m with these functions:
-
-```
-- (void)viewDidLoad
-{
- [super viewDidLoad];
- [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
- // Do any additional setup after loading the view from its nib.
- [[RemoteControls remoteControls] setWebView:self.webView];
-}
-
-- (void)viewDidUnload
-{
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
- // Turn off remote control event delivery
- [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
-}
-
-//add this function
-- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
- [[RemoteControls remoteControls] receiveRemoteEvent:receivedEvent];
- }
-```
-
-Then add this below `#import "MainViewController.h"` in `MainViewController.m`
-
-```
-#import "MainViewController.h"
-//import remoteControls
-#import "RemoteControls.h"
-
-@implementation MainViewController
-
-```
-
## Supported Platforms
- iOS
diff --git a/plugin.xml b/plugin.xml
index 9b5817e..ef52861 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -22,8 +22,6 @@
MIT License
- The MediaPlayer.framework should automatically be added, however you also need to add and modify a few functions in the MainViewContrller.m See the example in the README
-
@@ -32,6 +30,8 @@
+
+
diff --git a/src/ios/MainViewController+RemoteControls.h b/src/ios/MainViewController+RemoteControls.h
new file mode 100644
index 0000000..96b5961
--- /dev/null
+++ b/src/ios/MainViewController+RemoteControls.h
@@ -0,0 +1,12 @@
+//
+// MainViewController+RemoteControls.h
+//
+// Created by Julio Cesar Sanchez Hernandez on 4/3/16.
+//
+//
+
+#import "MainViewController.h"
+
+@interface MainViewController (RemoteControls)
+
+@end
diff --git a/src/ios/MainViewController+RemoteControls.m b/src/ios/MainViewController+RemoteControls.m
new file mode 100644
index 0000000..3212388
--- /dev/null
+++ b/src/ios/MainViewController+RemoteControls.m
@@ -0,0 +1,16 @@
+//
+// MainViewController+RemoteControls.m
+//
+// Created by Julio Cesar Sanchez Hernandez on 4/3/16.
+//
+//
+
+#import "MainViewController+RemoteControls.h"
+
+@implementation MainViewController (RemoteControls)
+
+- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"receivedEvent" object:receivedEvent];
+}
+
+@end
diff --git a/src/ios/RemoteControls.h b/src/ios/RemoteControls.h
index 53fd52b..0a42f62 100644
--- a/src/ios/RemoteControls.h
+++ b/src/ios/RemoteControls.h
@@ -15,9 +15,7 @@
@interface RemoteControls : CDVPlugin {
}
-+(RemoteControls*)remoteControls;
-
- (void)updateMetas:(CDVInvokedUrlCommand*)command;
-- (void)receiveRemoteEvent:(UIEvent *)receivedEvent;
+- (void)receiveRemoteEvent:(NSNotification *)notification;
@end
diff --git a/src/ios/RemoteControls.m b/src/ios/RemoteControls.m
index 5c9f5e3..2914bfa 100644
--- a/src/ios/RemoteControls.m
+++ b/src/ios/RemoteControls.m
@@ -16,6 +16,9 @@ @implementation RemoteControls
- (void)pluginInitialize
{
NSLog(@"RemoteControls plugin init.");
+ [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveRemoteEvent:) name:@"receivedEvent" object:nil];
+
}
- (void)updateMetas:(CDVInvokedUrlCommand*)command
@@ -83,7 +86,9 @@ - (void)updateMetas:(CDVInvokedUrlCommand*)command
}
-- (void)receiveRemoteEvent:(UIEvent *)receivedEvent {
+- (void)receiveRemoteEvent:(NSNotification *)notification {
+
+ UIEvent * receivedEvent = notification.object;
if (receivedEvent.type == UIEventTypeRemoteControl) {
@@ -126,23 +131,20 @@ - (void)receiveRemoteEvent:(UIEvent *)receivedEvent {
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options: 0 error: nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSString *jsStatement = [NSString stringWithFormat:@"if(window.remoteControls)remoteControls.receiveRemoteEvent(%@);", jsonString];
- [self.webView stringByEvaluatingJavaScriptFromString:jsStatement];
+#ifdef __CORDOVA_4_0_0
+ [self.webViewEngine evaluateJavaScript:jsStatement completionHandler:nil];
+#else
+ [self.webView stringByEvaluatingJavaScriptFromString:jsStatement];
+#endif
+
}
}
-+(RemoteControls *)remoteControls
-{
- //objects using shard instance are responsible for retain/release count
- //retain count must remain 1 to stay in mem
- if (!remoteControls)
- {
- remoteControls = [[RemoteControls alloc] init];
- }
-
- return remoteControls;
+-(void)dealloc {
+ [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedEvent" object:nil];
}
-
@end