Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JNA Objective-C(洛可可)日历回调_Java_Objective C_Jna_Ekeventkit_Rococoa - Fatal编程技术网

Java JNA Objective-C(洛可可)日历回调

Java JNA Objective-C(洛可可)日历回调,java,objective-c,jna,ekeventkit,rococoa,Java,Objective C,Jna,Ekeventkit,Rococoa,我想通过洛可可访问Java中的Objective-C EKEventStore。API指定了在用户接受日历访问提示时获得通知的方法,这在纯Objective-C中非常有效 Native.loadLibrary("EventKit", EventKitLibrary.class); EKEventStore store = EKEventStore.CLASS.alloc(); store.init(); //store = store.initWithAcces

我想通过洛可可访问Java中的Objective-C EKEventStore。API指定了在用户接受日历访问提示时获得通知的方法,这在纯Objective-C中非常有效

    Native.loadLibrary("EventKit", EventKitLibrary.class);

    EKEventStore store = EKEventStore.CLASS.alloc();
    store.init();
    //store = store.initWithAccessToEntityTypes(EKEntityType.EKEntityTypeEvent); // no notification
    EKEventStoreRequestAccessCompletionHandler handler = new EKEventStoreRequestAccessCompletionHandler() {
        @Override
        public void invoke(boolean granted, Pointer error) {
            System.out.println("Access: " + granted);
            NSArray calArray = store.calendarsForEntityType(EKEntityType.EKEntityTypeEvent);
            for (int i = 0; i < calArray.count(); i++) {
                NSObject calObject = calArray.objectAtIndex(i);
                EKCalendar osxcal = Rococoa.cast(calObject, EKCalendar.class);
                System.out.println(osxcal.title().toString());
            }
        }

    };
    ObjCObject object = Rococoa.proxy(handler); // get Objective C Callback Object to send
    store.requestAccessToEntityType_completion(EKEntityType.EKEntityTypeEvent, object.id());

    try {
        Thread.sleep(10000); // wait for the access prompt
    } catch (InterruptedException ex) {
    }

    // random object access to save instances from gc
    System.out.println(handler.toString());
    System.out.println(store.id());
    System.out.println(object.id());
映射类

public abstract class EKEventStore extends NSObject {

    public static final _Class CLASS = Rococoa.createClass("EKEventStore", _Class.class);

    public interface _Class extends ObjCClass {

        public abstract EKEventStore alloc();
    }

    public static interface EKEntityType {

        public static final int EKEntityTypeEvent = 0;
        public static final int EKEntityTypeReminder = 1;
    };

    public static interface EKEntityMask {

        public static final int EKEntityMaskEvent = (1 << EKEntityType.EKEntityTypeEvent);
        public static final int EKEntityMaskReminder = (1 << EKEntityType.EKEntityTypeReminder);
    };

    public abstract EKEventStore initWithAccessToEntityTypes(int EKEntityMask);

    public abstract EKEventStore init();

    public abstract void requestAccessToEntityType_completion(int EKEntityType, ID handler);

    interface EKEventStoreRequestAccessCompletionHandler {

        void invoke(boolean granted, Pointer error);
    }

    public abstract NSArray calendarsForEntityType(int EKEntityType);
}


public abstract class EKCalendar extends NSObject {

    public static final _Class CLASS = Rococoa.createClass("EKCalendar", _Class.class);

    public static interface _Class extends ObjCClass {

        public NSObject alloc();
    }

    public abstract NSString title();
}
公共抽象类EKEventStore扩展了NSObject{
公共静态最终类=Rococoa.createClass(“EKEventStore”,类);
公共接口_类扩展了objcc类{
公共抽象EKEventStore alloc();
}
公共静态接口eEntityType{
公共静态最终int eEntityTypeEvent=0;
公共静态最终int eEntityTypeReminder=1;
};
公共静态接口eEntityTask{

public static final int EKEntityMaskEvent=(1通常,
TypeMapper
是这样实现的,它将
指针
本机类型转换为其他Java类型:

class NSErrorTypeMapper extends DefaultTypeMapper {
    public NSErrorTypeMapper() {
        TypeConverter tc = new TypeConverter() {
            public Object toNative(Object value, ToNativeContext ctxt) {
                Pointer p = // convert your NSError "value" into a Pointer
                return p;
            }
            public Object fromNative(Object value, FromNativeContext ctxt) {
                Pointer p = (Pointer)value;
                Object object = // convert the pointer into an NSError object
                return object;    
            }
            public class nativeType() {
                return Pointer.class;
            }
        };
        addToNativeConverter(NSError.class, tc);
        addFromNativeConverter(NSError.class, tc);
    }
}

如果洛可可没有提供
指针
->
NSError
类型映射器,您当然可以使用
指针
作为参数类型,这至少可以让您成功执行回调,之后您可以研究处理
NSError
类型的最佳方式。可能从
指针
NSError
的正确转换。我以前也尝试过,但我在pc=0x00007fff8361c064,pid=19097,tid=5379,C[libobjc.a.dylib+0x9064]objc\u retain+0x14得到了一个JVM致命错误#SIGSEGV(0xb):si\u signo:11(SIGSEGV),si\u代码:0(未知),si_addr:0x000000000000使用这些结果更新您的问题,并准确描述您尝试的内容。好的,指针现在工作正常,函数调用正确,但回调函数从未执行
class NSErrorTypeMapper extends DefaultTypeMapper {
    public NSErrorTypeMapper() {
        TypeConverter tc = new TypeConverter() {
            public Object toNative(Object value, ToNativeContext ctxt) {
                Pointer p = // convert your NSError "value" into a Pointer
                return p;
            }
            public Object fromNative(Object value, FromNativeContext ctxt) {
                Pointer p = (Pointer)value;
                Object object = // convert the pointer into an NSError object
                return object;    
            }
            public class nativeType() {
                return Pointer.class;
            }
        };
        addToNativeConverter(NSError.class, tc);
        addFromNativeConverter(NSError.class, tc);
    }
}