浏览代码

Fix "objc[59448]: Cannot form weak reference to instance (0x60c000039440) of class RNCallKit. It is possible that this object was over-released, or is in the process of deallocation."

j8
Lyubo Marinov 7 年前
父节点
当前提交
f64b511682
共有 1 个文件被更改,包括 22 次插入2 次删除
  1. 22
    2
      ios/sdk/src/callkit/JMCallKitEmitter.swift

+ 22
- 2
ios/sdk/src/callkit/JMCallKitEmitter.swift 查看文件

@@ -34,9 +34,29 @@ internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
34 34
     }
35 35
 
36 36
     func removeListener(_ listener: JMCallKitListener) {
37
-        let wrapper = JMCallKitEventListenerWrapper(listener: listener)
38 37
         objc_sync_enter(listeners)
39
-        listeners.remove(wrapper)
38
+        // XXX Constructing a new JMCallKitEventListenerWrapper instance in
39
+        // order to remove the specified listener from listeners is (1) a bit
40
+        // funny (though may make a statement about performance) and (2) not
41
+        // really an option because the specified listener may already be
42
+        // executing its dealloc (like RNCallKit).
43
+        listeners.forEach {
44
+            // 1. JMCallKitEventListenerWrapper weakly references
45
+            //    JMCallKitListener so it may be nice to clean
46
+            //    JMCallKitEventListenerWrapperinstances up if they've lost
47
+            //    their associated JMCallKitListener instances (e.g. for
48
+            //    example, because whoever did addListener forgot to
49
+            //    removeListener). Unfortunately, I don't know how to do it
50
+            //    because JMCallKitEventListenerWrapper is a struct.
51
+            //
52
+            // 2. XXX JMCallKitEventListenerWrapper implements the weird
53
+            //    equality by JMCallKitListener hash which (1) I don't
54
+            //    understand and (2) I don't know how to invoke without
55
+            //    duplicating.
56
+            if ($0.hashValue == listener.hash) {
57
+                listeners.remove($0)
58
+            }
59
+        }
40 60
         objc_sync_exit(listeners)
41 61
     }
42 62
 

正在加载...
取消
保存