Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.rd11.remote-controls"
version="1.0.0">
version="1.0.1">

<engines>
<engine name="cordova" version=">=3.0.0" />
Expand All @@ -22,8 +22,6 @@

<license>MIT License</license>

<info>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</info>

<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="RemoteControls">
Expand All @@ -32,6 +30,8 @@
</config-file>
<header-file src="src/ios/RemoteControls.h" />
<source-file src="src/ios/RemoteControls.m" />
<header-file src="src/ios/MainViewController+RemoteControls.h" />
<source-file src="src/ios/MainViewController+RemoteControls.m" />
<framework src="MediaPlayer.framework" />
</platform>

Expand Down
12 changes: 12 additions & 0 deletions src/ios/MainViewController+RemoteControls.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// MainViewController+RemoteControls.h
//
// Created by Julio Cesar Sanchez Hernandez on 4/3/16.
//
//

#import "MainViewController.h"

@interface MainViewController (RemoteControls)

@end
16 changes: 16 additions & 0 deletions src/ios/MainViewController+RemoteControls.m
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions src/ios/RemoteControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
@interface RemoteControls : CDVPlugin {
}

+(RemoteControls*)remoteControls;

- (void)updateMetas:(CDVInvokedUrlCommand*)command;
- (void)receiveRemoteEvent:(UIEvent *)receivedEvent;
- (void)receiveRemoteEvent:(NSNotification *)notification;

@end
28 changes: 15 additions & 13 deletions src/ios/RemoteControls.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,7 +86,9 @@ - (void)updateMetas:(CDVInvokedUrlCommand*)command
}


- (void)receiveRemoteEvent:(UIEvent *)receivedEvent {
- (void)receiveRemoteEvent:(NSNotification *)notification {

UIEvent * receivedEvent = notification.object;

if (receivedEvent.type == UIEventTypeRemoteControl) {

Expand Down Expand Up @@ -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