Coder Social home page Coder Social logo

Comments (11)

aclev avatar aclev commented on July 17, 2024

Hi @manikkalra the only way to get progress on an upload is with the NSProgress object on the upload task. Can you provide an example of how you are attaching the observer? We can discuss other methods of obtaining progress for upload/download/async methods if you have suggestions.

from onedrive-sdk-ios.

 avatar commented on July 17, 2024

This is how I am using it. The class I am using it is a shared instance. So, I needed to find a way to remove the observer without deallocating the class. Hence, I removed the observer right before I added it again (this method is called every-time I upload). Is there something I may be missing?

 ODItemContentRequest *request = [[[[self.odClient drive] special:@"approot"] itemByPath:filename] contentRequest];
self.uploadTask = [request uploadFromData:jpegData completion:^(ODItem *item, NSError *error) {

                    [[[[[self.odClient drive] items:item.id] createLinkWithType:@"view"] request] executeWithCompletion:^(ODPermission *response, NSError *error) {

                            .........
                           NSString *sharedLink = response.link.webUrl;
                            dispatch_async(dispatch_get_main_queue(), ^{
                                success(sharedLink, item.id);
                            });
                    }];
            }];

            // Set up progress
            dispatch_async(dispatch_get_main_queue(), ^{

                [self removeObserver];
                [self.uploadTask.progress addObserver:self forKeyPath:NSStringFromSelector(@selector(fractionCompleted)) options:0 context:ProgressObserverContext];
            });

And here is how I remove the observer:

 -(void)removeObserver
{
    @try
    {
        [self.uploadTask.progress removeObserver:self forKeyPath:NSStringFromSelector(@selector(fractionCompleted)) context:ProgressObserverContext];
    }
    @catch (NSException * __unused exception) {}
}

from onedrive-sdk-ios.

aclev avatar aclev commented on July 17, 2024

Are you sure that the removeOberserver is getting called and not failing? You are catching an exception and not doing anything with it.

from onedrive-sdk-ios.

 avatar commented on July 17, 2024

If the observer is not yet set up, I expect it to fail. However, the removeObserver call will crash the app if not caught, and hence the empty catch statement.

from onedrive-sdk-ios.

aclev avatar aclev commented on July 17, 2024

You are calling removeOvserver before you have attached the observer. You need to remove the observer after the upload is complete.

from onedrive-sdk-ios.

 avatar commented on July 17, 2024

Here's what I am doing now. I'll test it a little more (KVO stops working after the app has been in the background for a while)

ODItemContentRequest *request = [[[[self.odClient drive] special:@"approot"] itemByPath:filename] contentRequest];
self.uploadTask = [request uploadFromData:jpegData completion:^(ODItem *item, NSError *error) {

                if (error)
                {
                    dispatch_async(dispatch_get_main_queue(), ^{

                        [self removeObserver];
                        err(error);
                    });
                }
                else
                {
                    dispatch_async(dispatch_get_main_queue(), ^{

                        [self removeObserver];
                        progress(1.0, YES);
                    });

                    [[[[[self.odClient drive] items:item.id] createLinkWithType:@"view"] request] executeWithCompletion:^(ODPermission *response, NSError *error) {

                        if(error)
                        {
                            dispatch_async(dispatch_get_main_queue(), ^{
                                err(error);
                            });
                        }
                        else
                        {
                            NSString *sharedLink = response.link.webUrl;
                            dispatch_async(dispatch_get_main_queue(), ^{
                                success(sharedLink, item.id);
                            });
                        }
                    }];
                }
            }];

            // Set up progress
            dispatch_async(dispatch_get_main_queue(), ^{

                [self.uploadTask.progress addObserver:self forKeyPath:NSStringFromSelector(@selector(fractionCompleted)) options:0 context:ProgressObserverContext];
            });

from onedrive-sdk-ios.

 avatar commented on July 17, 2024

So after some testing, the progress does not work after the app has gone into the background a few times. Any advice for me?

from onedrive-sdk-ios.

aclev avatar aclev commented on July 17, 2024

I haven't been able to reproduce your issue here, Can you try setting self.uploadTask to nil after your remove the observer?

from onedrive-sdk-ios.

 avatar commented on July 17, 2024

I will try that and let you know. Thank you!

from onedrive-sdk-ios.

 avatar commented on July 17, 2024

I tired that but unfortunately it doesn't help :\

from onedrive-sdk-ios.

kevklam avatar kevklam commented on July 17, 2024

Hi @manikkalra,
I am closing this issue as it has been inactive for a long time - please reopen if this needs further attention.
Thanks!

from onedrive-sdk-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.