私は、(現在プライベートの) C関数とCFNotificationCallback
コールバックブロックを使用して、CoreTelephony通知を待ち受けようとしています。SwiftのCFNotificationCallback、またはSwiftの@convention(c)ブロックを使用
マイブリッジのヘッダー(プライベートC関数をexternに):
#include <CoreFoundation/CoreFoundation.h>
#if __cplusplus
extern "C" {
#endif
#pragma mark - API
/* This API is a mimic of CFNotificationCenter. */
CFNotificationCenterRef CTTelephonyCenterGetDefault();
void CTTelephonyCenterAddObserver(CFNotificationCenterRef center, const void *observer, CFNotificationCallback callBack, CFStringRef name, const void *object, CFNotificationSuspensionBehavior suspensionBehavior);
void CTTelephonyCenterRemoveObserver(CFNotificationCenterRef center, const void *observer, CFStringRef name, const void *object);
void CTTelephonyCenterRemoveEveryObserver(CFNotificationCenterRef center, const void *observer);
void CTIndicatorsGetSignalStrength(long int *raw, long int *graded, long int *bars);
#pragma mark - Definitions
/* For use with the CoreTelephony notification system. */
extern CFStringRef kCTIndicatorsSignalStrengthNotification;
#if __cplusplus
}
#endif
マイスウィフトコード:
let callback: CFNotificationCallback = { (center: CFNotificationCenter?, observer: UnsafeRawPointer?, name: CFString?, object: UnsafeRawPointer?, info: CFDictionary?) -> Void in
// ...
}
CTTelephonyCenterAddObserver(CTTelephonyCenterGetDefault().takeUnretainedValue(), nil, callback, kCTIndicatorsSignalStrengthNotification.takeUnretainedValue(), nil, .coalesce)
しかし、私は私のcompletion
変数の署名が一致して取得することはできませんタイプ番号のCFNotificationCallback
の要件
Cannot convert value of type '(CFNotificationCenter?, UnsafeRawPointer?, CFString?, UnsafeRawPointer?, CFDictionary?) -> Void' to specified type 'CFNotificationCallback' (aka '@convention(c) (Optional<CFNotificationCenter>, Optional<UnsafeMutableRawPointer>, Optional<CFNotificationName>, Optional<UnsafeRawPointer>, Optional<CFDictionary>) ->()')
どのように私は、スウィフトにうまくプレーする@convention(c)
閉鎖を得ることができますか?コンパイラはクロージャの署名が正常に動作推測まかせ
'observer'が' UnsafeMutableRawPointer'で、 'UnsafeRawPointer'ではないので、コンパイルされません。 –