Archived Forum Post

Index of archived forum posts

Question:

Event Callbacks in IOS / Objective-C

Sep 02 '12 at 03:53

Is progress monitoring and abort capability available in iOS and MacOSX? I didn't find them.


Answer

Yes. To implement an event callback, your app would define and implement a class that inherits from one of the CkoProgress base classes. You provide method implementations to override the methods specified in the CkoProgress classes (see the header files). The callback object is specified via the EventCallbackObject property:

// property setter: EventCallbackObject
 - (void)setEventCallbackObject: (CkoFtp2Progress *)eventObj;

For example, here are sample source files for HTTP event callbacks:

MyHttpProgress.h:


#import "../workspace/chilkat/ObjectiveC/CkoHttpProgress.h"

@interface MyHttpProgress : CkoHttpProgress {

}

- (id)init; - (void)dealloc; - (void)dispose;

- (void)AbortCheck: (BOOL *)abort; - (void)PercentDone: (NSNumber *)pctDone abort: (BOOL *)abort;

@end

MyHttpProgress.mm:


#import "MyHttpProgress.h"

@implementation MyHttpProgress

-(id)init { self = [super init]; return self; }

-(void)dealloc { [super dealloc]; }

-(void)dispose { }

- (void)AbortCheck: (BOOL *)abort { *abort = NO; // Set this to YES to abort the operation in progress.

// Add your application code here...

} - (void)PercentDone: (NSNumber *)pctDone abort: (BOOL *)abort { *abort = NO; // Set this to YES to abort the operation in progress.

    // Add your application code here...

}

@end


Answer

Also, the AbortCheck event is standard to all classes that have event callbacks.

The HeartbeatMs property is the number of milliseconds between each AbortCheck callback. The default value is 0 to indicate that no AbortCheck events will be fired. You must set the HeartbeatMs property to a non-zero value to receive AbortCheck events. For example, a value of 100 sends 10 events per second.

Important: Many Chilkat methods allow for percent-done progress monitoring. Percent-done event callbacks also provide the ability to abort an operation. Therefore, AbortCheck events are suppressed when the frequency of percent-done callbacks is greater than the HeartbeatMs. The reason for this is to prevent too many callbacks from disrupting performance. If you used both percent-done and AbortCheck events, you should also code for aborting from the percent-done event.


Answer

I can assure you that the event callbacks are happening during the call to DownloadFileByName. The problem is that (for some reason) your UI is not refreshing with whatever code you've provided in the event callback.

To prove that the event callbacks are happening during the call to DownloadFileByName, do the following:

1) Open a log file just prior to calling DownloadFileByName, write the line "About to call DownloadFileByName", and then close the log file.
2) In your event callback, open the same log file for append, write a line with information for the event callback, and close the log file.
3) Just after the call to DownloadFileByName, do the same: open the log file for append, write the line "Finished calling DownloadFileByName", and close the log file.

Run your app again. You'll find that the event callbacks lines appear between the lines logged just before and after the call to DownloadFileByName.

I'm sorry to say that providing general programming help for writing UI interfaces for IOS in Objective-C is not something Chilkat can do. I can help you in achieving the event callback, and that is already achieved. The final step is entirely application code (non-Chilkat) which involves using that information to update the UI. This is something for which I cannot help.


Answer

Ray,

I'm sorry to say it's not something that can be changed. Small files that upload or download very quickly will certainly not have callbacks for every 1% -- it's just not possible. The callbacks happen at fairly regular intervals, and it would be disruptive to make callbacks too frequently. (For example, if the entire download happens in 1 second, it's pointless to have more than a few callbacks.) However, for very large files, you should see PercentDone callbacks for every 1%.