From 7abb711650a6e26a4d2eac35be395be231b2a553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Fri, 4 Mar 2016 20:35:39 +0100 Subject: [PATCH 1/5] Added cordova iOS 4+ support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added cordova iOS 4 support. Moved most parts of MainViewController.m to the plugin class so the plugin user doesn’t have to add them. Removed the RemoteControls singleton and used the NSNotificationCenter to pass the event to the RemoteControls class. --- README.md | 23 +++-------------------- src/ios/RemoteControls.h | 4 +--- src/ios/RemoteControls.m | 28 +++++++++++++++------------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 150f884..00a3e33 100644 --- a/README.md +++ b/README.md @@ -13,30 +13,13 @@ Add the plugin much like any other: `cordova plugin add com.rd11.remote-controls` -#### Modify the MainViewController.m with these functions: +#### Modify the MainViewController.m to add this function: ``` -- (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]; - } + [[NSNotificationCenter defaultCenter] postNotificationName:@"receivedEvent" object:receivedEvent]; +} ``` Then add this below `#import "MainViewController.h"` in `MainViewController.m` 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..bec69e2 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 From a92ed87af840b49c9e80288be3157b8069b8a40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Fri, 4 Mar 2016 20:39:37 +0100 Subject: [PATCH 2/5] formatting --- src/ios/RemoteControls.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/RemoteControls.m b/src/ios/RemoteControls.m index bec69e2..2914bfa 100644 --- a/src/ios/RemoteControls.m +++ b/src/ios/RemoteControls.m @@ -144,7 +144,7 @@ - (void)receiveRemoteEvent:(NSNotification *)notification { -(void)dealloc { [[UIApplication sharedApplication] endReceivingRemoteControlEvents]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedEvent" object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedEvent" object:nil]; } @end From d80cf0e455c7d3f10de2130ab868bd3f95de4dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Fri, 4 Mar 2016 23:19:30 +0100 Subject: [PATCH 3/5] Added a MainViewController category Added a MainViewController category to avoid the manual step of adding remoteControlReceivedWithEvent method --- README.md | 20 -------------------- plugin.xml | 2 ++ src/ios/MainViewController+RemoteControls.h | 12 ++++++++++++ src/ios/MainViewController+RemoteControls.m | 16 ++++++++++++++++ 4 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 src/ios/MainViewController+RemoteControls.h create mode 100644 src/ios/MainViewController+RemoteControls.m diff --git a/README.md b/README.md index 00a3e33..7361d8b 100644 --- a/README.md +++ b/README.md @@ -13,26 +13,6 @@ Add the plugin much like any other: `cordova plugin add com.rd11.remote-controls` -#### Modify the MainViewController.m to add this function: - -``` -//add this function -- (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent { - [[NSNotificationCenter defaultCenter] postNotificationName:@"receivedEvent" object: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..d28eadc 100644 --- a/plugin.xml +++ b/plugin.xml @@ -32,6 +32,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 From df60594e9acc4a43588a8942c9ad719c6d3eaa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20C=C3=A9sar?= Date: Sat, 5 Mar 2016 11:10:59 +0100 Subject: [PATCH 4/5] Removed info tag from plugin.xml Removed info tag from plugin.xml as manual modifications are no longer necessary --- plugin.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index d28eadc..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 - From f557e3cc8f490fb9fce850d9b9fd68330e6f6259 Mon Sep 17 00:00:00 2001 From: shi11 Date: Thu, 14 Apr 2016 21:34:58 -0400 Subject: [PATCH 5/5] bumping version --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index ef52861..de207dd 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="1.0.1">