Access NSLog through Cgo for iOS NetworkExtension logging

This commit is contained in:
Neil Alexander 2019-01-05 21:59:07 +00:00
parent 6bbd8c1b30
commit 87362a21e2
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 32 additions and 3 deletions

View file

@ -0,0 +1,25 @@
// +build mobile,darwin
package yggdrasil
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
void Log(const char *text) {
NSString *nss = [NSString stringWithUTF8String:text];
NSLog(@"%@", nss);
}
*/
import "C"
import "unsafe"
type MobileLogger struct {
}
func (nsl MobileLogger) Write(p []byte) (n int, err error) {
p = append(p, 0)
cstr := (*C.char)(unsafe.Pointer(&p[0]))
C.Log(cstr)
return len(p), nil
}