SKPSMTPMessage和UIProgressView

时间:2011-06-07 19:58:24

标签: iphone email background smtp uiprogressview

我正在使用此库(http://code.google.com/p/skpsmtpmessage/)在我的iPhone应用中发送电子邮件

如何在发送过程中实现UIProgressView?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

  1. 1.在你的.h中创建你的UIProgressView以及BOOL和NSTimer 一个函数调用它updateProgress

    2.在.m文件中合成

    3.在你的“viewDidLoad”中将BOOL的初始值设置为NO,并创建一个 计时器

  2. 您的.h文件应包含

    UIProgressView * progressView;
    BOOL emailSent;
    NSTimer * timer;
    
    -(void)updateProgress;
    @property(nonatomic, retain)UIProgressView * progressView;
    @property(nonatomic, assign)BOOL emailSent;
    @property(nonatomic, retain)NSTimer * timer;
    

    您的.m文件应包含

    @synthesize progressView, emailSent,timer;
    
    //viewdidload
    //set initial value to no
    emailSent = NO;
    
    //since we cant interact with UIElements on anything but the Main thread we use a timer
    //because you are probably sending the email in a seperate thread
    timer= [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];
    
    //create this function
    -(void)updateProgress{
    
    
        //wait for email to be done
        if (emailSent == NO) {
    
    // you'll have to tweak this area to get the correct data "progress"    
    float fullValue = .0032;
    int progressInt = (app.parsedCount * z);
    
    //progressInt is the representation of how much data has been completed.
            progressView.progress = progressInt;
        }
        else {
    
        //email is done 
        emailSent = YES;
    
            //kill the timer so it doesnt continue to run
        [timer invalidate];
        //email sent so you can remove your progress view
             [self.view removeSubView:progressView];
        }
    }
    

    快乐的编码!