2012-09-14 2 views
0

진행률 표시 줄은 배달 된 이메일의 비율을 표시하는 데 사용됩니다. 전자 libetpan.xcodeproj을 사용하여 전자 메일을 보내고 백분율은 다음 코드로 계산할 수 있습니다. 그것은 c로 기록되어있다. 문제는 c.file에 알림을 게시하여 비율이 증가했다는 관찰자 (objective-c 클래스)에게 어떻게 알릴 수 있습니까? 어떤 도움에 감사드립니다 :).c 파일에 알림 게시

mailstream_helper.c

static inline int send_data_crlf_progress(mailstream * s, 
         const char *message, size_t size, 
         int quoted, size_t progr_rate, 
         progress_function * progr_fun, 
         mailprogress_function * 
         progr_context_fun, void *context) 
{ 
    const char *current; 
    size_t count; 
    size_t last; 
    size_t remaining; 

    count = 0; 
    last = 0; 

    current = message; 
    remaining = size; 

    int i = 0; 
    while (remaining > 0) { 
     ssize_t length; 

     if (quoted) { 
      if (current[0] == '.') 
       if (mailstream_write(s, ".", 1) == -1) 
        goto err; 
     } 

     length = send_data_line(s, current, remaining); 
     if (length < 0) 
      goto err; 

     current += length; 

     count += length; 
     if (progr_rate != 0) { 
      if (count - last >= progr_rate) { 
       if (progr_fun != NULL) { 
        (*progr_fun) (count, size); 
       } 
       if (progr_context_fun != NULL) { 
        (*progr_context_fun) (count, size, context); 
       } 
       last = count; 
      } 
     } 

     remaining -= length; 
     //I need to post a notification here to let my 
      //progress bar know how much data has been sent.   
     printf("No.%d rateOfSentData:%d end\r\n", ++i, 
       1.0 - (float) remaining/(float) size); 

    } 

    return 0; 

err: 
    return -1; 
} 

답변

1

하는 .m 확장자를 가지고 파일의 이름을 바꿉니다. 지금은 순수한 C 코드가있는 ObjC 파일입니다 (현재). 그런 다음 NSNotificationCenter를 사용하여 다른 곳에서와 마찬가지로 알림을 보내려면 끝에 메시지를 추가하십시오.

어떤 이유로이 이름을 바꿀 수없는 경우 알림을 위해 기존 .m 파일에 추가하는 c 함수를 호출해야합니다.

+0

우리는 파일 이름을 .m 접미어로 바꾸어 문제를 해결합니다. 그것은 지금 잘 작동 :) 많은 감사합니다 :) –