Comments (11)
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.
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.
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.
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.
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.
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.
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.
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.
I will try that and let you know. Thank you!
from onedrive-sdk-ios.
I tired that but unfortunately it doesn't help :\
from onedrive-sdk-ios.
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)
- library not found for -lADAL HOT 2
- OneDrive for Business - New Apps will not work due to Office 365 Discovery API Deprecation HOT 10
- Streamable path of file HOT 1
- Download thumbnail HOT 2
- improvement: Supply thumbnail urls in item request instead of having a separate request
- nameConflict not work
- Is this sdk outdated? HOT 5
- Discovery API will be deprecated
- One Drive Login PresentContrller iOS13
- Deprecated API Usage (UIWebView) HOT 6
- Urgent :: Use of deprecated ADAL version HOT 11
- IOS onedrive SDK needs to be updated. Uiwebview has been abandoned and needs to be replaced with wkwebview HOT 1
- Can't Sign in with MS account HOT 2
- Install without pods ?
- H
- Asd
- P
- webDavUrl does not work in mobile platform
- OneDrive SDK for iOS
- OneDrive for Business cTag not updated when folder contents changes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onedrive-sdk-ios.