2012-03-26 3 views
2

iOS의 phonegap에서 맞춤 이벤트를 실행하려고합니다. 이제까지 내가 한 일은 다음과 같습니다. 맞춤 플러그인을 만들었으므로 자바 스크립트에서 내 플러그인을 호출 할 수 있으며 모든 플러그인이 제대로 작동합니다. 기본적으로 플러그인은 모국어 기능을 제공하는 ModalViewController를 표시합니다. 동영상 녹화 및 편집과 같이 일단 사용자가 YouTube에 비디오를 업로드하면 완료됩니다. 다운로드가 완료되면 이벤트를 시작하고 싶지만 현재로서는이 작업을 수행 할 수 없습니다.
이것은 내가 사용하는 코드의 일부입니다 :
내 index.html에서이 함수는 버튼 클릭만으로 트리거됩니다. (저는 자바 스크립트 개발자가 아닙니다) nativeFunction은 기본적으로 내 사용자 정의 플러그인을 호출합니다. 나는 두 가지 방법이PhoneGap iOS에서 맞춤 이벤트 실행

var MyClass = { 
    nativeFunction: function(types, success, fail) { 
    return Cordova.exec(success, fail, "MyClass", "showInterface", types); 
    } 
} 

내부 MyClass.m :

function testCustomPlugin() 
{ 
    MyClass.nativeFunction(
          function(result) { 
          alert("Success : \r\n"+result);  
          }, 
          function(error) { 
          alert("Error : \r\n"+error);  
          } 
    ); 
    document.addEventListener("post_sent",onPostSent,false); 
} 
function onPostSent() 
{ 
    alert("post sent"); 
} 

내 MyClass.js입니다 showInterface 및 sendNotification에,

showInterface.m을

- (void) showInterface:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options 
{ 
    self.callbackID = [arguments objectAtIndex:0]; 
    // missing code 
    [[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(sendSuccessNotification:) 
              name:@"PostSentNotification" object:nil]; 
} 

-(void)sendSuccessNotification:(NSNotification *)notification 
{ 
    if (self.callbackID) { 
    NSLog(@"%@",callbackID); 
    NSLog(@"sendSuccessNotification"); 

    NSDictionary *dictionary = [NSDictionary dictionaryWithObject:@"testCallBack" 
              forKey:@"returnValue"]; 
    CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 
              messageAsDictionary:dictionary 
    [result setKeepCallbackAsBool:YES]; 
    [super writeJavascript:[result toSuccessCallbackString:self.callbackID]]; 
    } 

} 

내가 할 수있는 내 로그에서 sendSuccessNotification이 호출되었지만 이벤트가 시작되지 않았 음을 확인하십시오. 나는 wro를 할 것이라고 확신합니다. 자바 스크립트에서 ng하지만 문제는 내가 무엇을 모른다는 것입니다.

답변

0

를이 튜토리얼을 다음 (또는 프로젝트를 다운로드하고 거기에서 그것을 가지고하는 것이 좋습니다 귀하의 코드, 나는 PhoneGap/Cordova 1.5.0을 사용하고 있다고 생각합니다. 맞습니까? 버전 1.6.0에서 많은 코드가 변경 되었기 때문에 묻습니다. 제 생각에는

다음 줄이 잘못되었습니다 : 당신은 문자열 값을 디버깅하여 자신을 확인할 수 있습니다

self.callbackID = [arguments objectAtIndex:0]; 

. 나의 정보에 의하면 다음과 같은 성명은 결과 객체에 대한 올바른 콜백 ID를 검색하는 데 사용되어야한다

또한
self.callbackID = [arguments pop]; 

, 당신이 당신의 Cordova.plist에 플러그인을 등록했는지 확인하십시오. 호프가 문제를 해결하기를 바랍니다.

최고 마틴

관련 문제