0

进度条用于向我们显示已发送的电子邮件百分比。我libetpan.xcodeproj用来发送电子邮件,百分比可以在下面的代码中计算。它是用c写的。问题是我如何在 c.file 中发布通知来告诉观察者(它是一个 Objective-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;
}
4

1 回答 1

2

将文件重命名为具有 .m 后缀。它现在是一个包含纯 C 代码的 ObjC 文件(现在)。然后在末尾添加一条消息以发送通知,就像在其他地方使用 NSNotificationCenter 一样。

如果由于某种原因无法重命名,请调用 ac 函数,然后将其添加到现有的 .m 文件中以进行通知。

于 2012-09-14T12:12:22.030 回答