Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes memory leak created by Apple’s interoperability #85

Merged
1 commit merged into from
Feb 12, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions Classes/Managers/PlayKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public class PlayKitManager: NSObject {
return loader
}

public func registerPlugin(_ pluginClass: PKPlugin.Type) {
pluginRegistry[pluginClass.pluginName] = pluginClass
public func registerPlugin(_ pluginClass: Plugin.Type) {
guard let pluginType = pluginClass as? PKPlugin.Type else {
fatalError("plugin class must be of type PKPlugin")
}
pluginRegistry[pluginType.pluginName] = pluginType
}

func createPlugin(name: String, player: Player, pluginConfig: Any?, messageBus: MessageBus) -> PKPlugin? {
Expand Down
1 change: 1 addition & 0 deletions Classes/Player/AVPlayerEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class AVPlayerEngine: AVPlayer {
self.onEventBlock = nil
// removes app state observer
AppStateSubject.sharedInstance.remove(observer: self)
self.replaceCurrentItem(with: nil)
self.isDestroyed = true
}

Expand Down
13 changes: 12 additions & 1 deletion Classes/Plugins/PKPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@
import UIKit
import AVFoundation

/**
Used as a workaround for Apple bug with swift interoperability.

There is an issue with initializing an object based on a protocol.Type with @objc attribute.
Therefore we use a wrapper protocol for PKPlugin with @objc and then casting to a PKPlugin without the @objc attribute.

- important:
**should not be used! use PKPlugin to add a plugin**
*/
@objc public protocol Plugin {}

/// The `PKPlugin` protocol defines all the properties and methods required to define a plugin object.
@objc public protocol PKPlugin {
public protocol PKPlugin: Plugin {
/// The plugin name.
static var pluginName: String { get }
/// The associated media entry.
Expand Down