react-native-airplay-module 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,12 @@
2
2
  #import <AVFoundation/AVFoundation.h>
3
3
  #import <AudioToolbox/AudioToolbox.h>
4
4
  #import <AVKit/AVKit.h>
5
+ #import <React/RCTLog.h>
6
+ #import <React/RCTUtils.h>
7
+
8
+ @interface AirplayModule () <AVRoutePickerViewDelegate>
9
+ @property(nonatomic, strong) AVRoutePickerView *routePickerView;
10
+ @end
5
11
 
6
12
  @implementation AirplayModule
7
13
  @synthesize bridge = _bridge;
@@ -31,17 +37,47 @@ RCT_EXPORT_METHOD(disconnect) {
31
37
  RCT_EXPORT_METHOD(openMenu)
32
38
  {
33
39
  dispatch_async(dispatch_get_main_queue(), ^{
34
- AVRoutePickerView *routePickerView = [[AVRoutePickerView alloc] init];
40
+ if (self.routePickerView.window != nil) {
41
+ return;
42
+ }
43
+
44
+ UIViewController *presenter = RCTPresentedViewController();
45
+ if (presenter.viewIfLoaded.window == nil) {
46
+ RCTLogWarn(@"AirPlay route picker requires a visible presenting view.");
47
+ return;
48
+ }
49
+
50
+ // Give AVKit an explicit window/presenter and keep its anchor alive until
51
+ // dismissal instead of relying on an unattached, temporary picker.
52
+ AVRoutePickerView *routePickerView =
53
+ [[AVRoutePickerView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
54
+ self.routePickerView = routePickerView;
55
+ routePickerView.delegate = self;
56
+ [presenter.view addSubview:routePickerView];
57
+ [routePickerView layoutIfNeeded];
58
+
35
59
  for (UIView *subview in routePickerView.subviews) {
36
60
  if ([subview isKindOfClass:[UIButton class]]) {
37
61
  UIButton *button = (UIButton *)subview;
38
62
  [button sendActionsForControlEvents:UIControlEventTouchUpInside];
39
- break;
63
+ return;
40
64
  }
41
65
  }
66
+
67
+ RCTLogWarn(@"AirPlay route picker did not create its route button.");
68
+ [routePickerView removeFromSuperview];
69
+ self.routePickerView = nil;
42
70
  });
43
71
  }
44
72
 
73
+ - (void)routePickerViewDidEndPresentingRoutes:(AVRoutePickerView *)routePickerView
74
+ {
75
+ [routePickerView removeFromSuperview];
76
+ if (self.routePickerView == routePickerView) {
77
+ self.routePickerView = nil;
78
+ }
79
+ }
80
+
45
81
  - (void)routeChanged:(NSNotification *)sender {
46
82
  [self sendInformations];
47
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-airplay-module",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "React Native Airplay module",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
12
12
  s.authors = package["author"]
13
13
 
14
14
  s.platforms = { :ios => min_ios_version_supported }
15
- s.source = { :git => "https://github.com/Spicy-Sparks/react-native-airplay-module.git", :tag => "#{s.version}" }
15
+ s.source = { :git => "https://github.com/Spicy-Sparks/react-native-airplay-module.git", :tag => "v#{s.version}" }
16
16
 
17
17
  s.source_files = "ios/**/*.{h,m,mm}"
18
18