进度条用于向我们显示已发送的电子邮件百分比。我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;
}