0

There's a crash in parameter casting:

Could not cast value of type NSStackBlock (0x1030b1e78) to '(__C.UNNotificationPresentationOptions) -> ()' (0x1030b0208). 2018-02-19 17:40:31.204021+0200 [2407:480530]

Could not cast value of type NSStackBlock (0x1030b1e78) to '(C.UNNotificationPresentationOptions) -> ()' (0x1030b0208).

extension Reactive where Base: UNUserNotificationCenter {

public var delegate: DelegateProxy<UNUserNotificationCenter, UNUserNotificationCenterDelegate> {
    return RxNotificationServiceDelegateProxy.proxy(for: base)
}

var didReceiveResponce: Observable<UNNotificationResponse> {
    return delegate.methodInvoked(#selector(UNUserNotificationCenterDelegate.userNotificationCenter(_:didReceive:withCompletionHandler:))).map { parameters in
        return parameters[1] as! UNNotificationResponse
    }
}

var willPresentNotification: Observable<((UNNotificationPresentationOptions) -> Void)> {
    return delegate.methodInvoked(#selector(UNUserNotificationCenterDelegate.userNotificationCenter(_:willPresent:withCompletionHandler:))).map { parameters in
        return parameters[2] as! ((UNNotificationPresentationOptions) -> Void) **CRASH!!!**
    }
}
}

All I need is to show localNotifications in the foreground, so delegate method needed accordingly, but can not figure out how to do so I can pass the closure as a parameter to an Observable or if it's not possible or not needed I will be glad to read about your way of solving such issue in RxSwift manner.

Gaurav Bharti
  • 1,065
  • 1
  • 14
  • 22
  • What if you cast as `@convention(block) (UNNotificationPresentationOptions) ->()` ? – Valérian Feb 19 '18 at 19:57
  • crash but with a bit different log: Could not cast value of type '__NSStackBlock__' (0x7f8e3982a188) to '@convention(block) (__C.UNNotificationPresentationOptions) -> ()' (0x7f8e3982a998). – Dmitriy Ivashin Feb 20 '18 at 06:59
  • Sorry, can't help more. Anyway, this seems unrelated to RxSwift at all. I would post another question on how to cast NSStackBlock to a swift closure... – Valérian Feb 20 '18 at 08:44
  • Thanks, must be you're right, but chances are that someone run into similar issue writing Rx extensions – Dmitriy Ivashin Feb 20 '18 at 10:31

0 Answers0