I'm trying to upload image to Adobe Creative Cloud using method create:folder:dataPath:contentType:progressBlock:successBlock:cancellationBlock:errorBlock of AdobeAssetFile. File upload succesfully, but I can't track upload progress with progressBlock. This block just don't invocated.
- (void)sendImageWithURL:(NSURL *)imageURL {
NSString *imageName = [imageURL lastPathComponent];
[AdobeAssetFile create:imageName
folder:[AdobeAssetFolder root]
dataPath:imageURL
contentType:[AdobeAssetMimeTypes mimeTypeForExtension:#"jpg"]
collisionPolicy:AdobeAssetFileCollisionPolicyAppendUniqueNumber
progressBlock:^(double fractionCompleted) {
NSLog(#"Progress: %f", fractionCompleted);
}
successBlock:^(AdobeAssetFile *file) {
NSLog(#"Operation is complete");
}
cancellationBlock:^{
NSLog(#"Operation is canceled");
}
errorBlock:^(NSError *error){
NSLog(#"Error is occur: %#", error.localizedDescription);
}
];
}
What's wrong with this code? And why progressBlock not invocated?
I'm using Adobe Creative SDK v0.13.2139.
There is nothing wrong with your code. This is a known issue. A fix is in the works.
Related
I need to upload a file to firebase, firebase account is set, iOS project is connecting...
The file exists, and I check for file size before sending...
when I try the upload the process starts, but I get the error:
Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response
This is the path for the file:
/var/mobile/Containers/Data/PluginKitPlugin/A14B0460-06E7-4EC0-80CE-9C27B5B70BC2/Documents/img.JPG
My doubt is if I have "riversRef" property correctly set?... What is missing?
- (void)uploadFileTest:(NSURL*)url {
// reference
FIRStorage * storage = [FIRStorage storage];
// Create a root reference
FIRStorageReference *storageRef = [storage reference];
FIRStorageReference *riversRef = [storageRef child:#"images/rios.jpg"]; // is this correct?
FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] init];
metadata.contentType = #"image/jpeg";
NSLog(#"storageRef: %#", storageRef);
NSLog(#"url path: %#", [url path]);
NSLog(#"metadata : %#", metadata);
//object size?
if ([[NSFileManager defaultManager] fileExistsAtPath:[url path]]){
long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:url.absoluteString error:nil][NSFileSize] longLongValue];
NSLog(#"sik: %lld", fileSize);
}else{
NSLog(#"nanais");
}
NSURL *curaul = [NSURL fileURLWithPath:[url path]];
// Upload file and metadata to the object 'images/rios.jpg'
FIRStorageUploadTask *uploadTask = [riversRef putFile:curaul metadata:metadata];
// Listen for state changes, errors, and completion of the upload.
[uploadTask observeStatus:FIRStorageTaskStatusResume handler:^(FIRStorageTaskSnapshot *snapshot) {
// Upload resumed, also fires when the upload starts
NSLog(#"upload started");
}];
[uploadTask observeStatus:FIRStorageTaskStatusPause handler:^(FIRStorageTaskSnapshot *snapshot) {
// Upload paused
NSLog(#"paused");
}];
[uploadTask observeStatus:FIRStorageTaskStatusProgress handler:^(FIRStorageTaskSnapshot *snapshot) {
// Upload reported progress
double percentComplete = 100.0 * (snapshot.progress.completedUnitCount) / (snapshot.progress.totalUnitCount);
NSLog(#"percentComplete :: %f", percentComplete);
}];
[uploadTask observeStatus:FIRStorageTaskStatusSuccess handler:^(FIRStorageTaskSnapshot *snapshot) {
// Upload completed successfully
NSLog(#"successfully");
}];
// Errors only occur in the "Failure" case
[uploadTask observeStatus:FIRStorageTaskStatusFailure handler:^(FIRStorageTaskSnapshot *snapshot) {
NSLog(#"errore :: %#", snapshot.error.description);
if (snapshot.error != nil) {
switch (snapshot.error.code) {
case FIRStorageErrorCodeObjectNotFound:
// File doesn't exist
break;
case FIRStorageErrorCodeUnauthorized:
// User doesn't have permission to access file
break;
case FIRStorageErrorCodeCancelled:
// User canceled the upload
break;
/* ... */
case FIRStorageErrorCodeUnknown:
// Unknown error occurred, inspect the server response
break;
}
}
}];
}
Is the response to unknown error?
How to fix upload?, thanks
I want to share a post on Pintrest( i.e. want to pin from my app). I have used its SDK using Cocoa Pod. I'm able to pin (share) sometimes but sometimes while pinning it app crashes on random basis and getting nothing in crash log.
Can anyone tell me what is going wrong ? I'm adding the code snippet that i have used...I have used this link to install the SDK and followed this link. https://github.com/pinterest/ios-pdk
-(IBAction)pintrestButtonTapped
{
#try
{
[PDKClient configureSharedInstanceWithAppId:#"4841203782190640720"];
[[PDKClient sharedInstance] authenticateWithPermissions:#[PDKClientReadPublicPermissions,
PDKClientWritePublicPermissions,
PDKClientReadPrivatePermissions,
PDKClientWritePrivatePermissions,
PDKClientReadRelationshipsPermissions,
PDKClientWriteRelationshipsPermissions]
withSuccess:^(PDKResponseObject *responseObject)
{
[PDKPin pinWithImageURL:[NSURL URLWithString:#"https://www.respectnetwork.com/wp-content/uploads/cynja-app_store_share.jpg"]
link:[NSURL URLWithString:#"https://itunes.apple.com/us/app/cynjaspace/id1050628761?ls=1&mt=8/"]
suggestedBoardName:#"CynzaSpace"
note:kSocialMediaSharingText
withSuccess:^
{
NSLog(#"Successfully Pinned Up!!");
}
andFailure:^(NSError *error)
{
NSLog(#"UnSuccessfull");
}];
}
andFailure:^(NSError *error)
{
NSLog(#"authentication failed: %#", error);
}];
}
#catch (NSException *exception)
{
// Print exception information
NSLog( #"NSException caught" );
NSLog( #"Name: %#", exception.name);
NSLog( #"Reason: %#", exception.reason );
return;
}
}
I tried to download file from google drive API since 3 day without success. I used this https://developers.google.com/drive/ios/devguide/files#reading_files.
But I can't understand what I need to put in *drive and *file?
I tried :
GTLDriveFile *file = #"fileText.txt"; (or I tried the url of my file on google drive...) The guide don't explain... And I didn't find real example.
GTLServiceDrive *drive = ...;
GTLDriveFile *file = ...;
NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media",
file.identifier]
GTMSessionFetcher *fetcher = [drive.fetcherService fetcherWithURLString:url];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
// Do something with data
} else {
NSLog(#"An error occurred: %#", error);
}
}];
So I had search other code like but no one explain what I need to put in drive and file:
how to download file from google drive using objective c? (just this say it's url)
Google drive api download file for iOS
IOS: How to Download Google Docs files using ios google drive sdk API?
SOLUTION :
I had a problem of authorization with my scope, solved by total access to drive. I changed the scope (in quickstart code, look : "- (GTMOAuth2ViewControllerTouch *)createAuthController...")
-->NSArray *scopes = [NSArray arrayWithObjects:kGTLAuthScopeDrive, nil];
For download (inspired by quickstart example) :
// self.service is my GTLServiceDrive
// When the view appears, ensure that the Drive API service is authorized, and perform API calls.
- (void)viewDidAppear:(BOOL)animated {
if (!self.service.authorizer.canAuthorize) {
// Not yet authorized, request authorization by pushing the login UI onto the UI stack.
[self presentViewController:[self createAuthController] animated:YES completion:nil];
} else {
NSString *urltest = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media", identifier_file]; //the ID of my file in a string identifier_file
GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:urltest]; // the request
// receive response and play it in web view:
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *errorrr) {
if (errorrr == nil) {
NSLog(#"Retrieved file content");
[webView_screen loadData:data MIMEType:#"application/pdf" textEncodingName:#"UTF-8" baseURL:nil]; //my file is a pdf
[webView_screen reload];
} else {
NSLog(#"An error occurred: %#", errorrr);
}
}];
}
}
If you want to save on the phone, you can look the Bala's code.
First fetch the file from Drive
driveFiles = [[NSMutableArray alloc] init];
for (GTLDriveFile *file in files.items) {
if ([file.mimeType isEqualToString:#"application/vnd.google-apps.folder"]) {
} else {
NSString *fileExtension = file.fileExtension;
if (fileExtension) {
if ([fileExtension isEqualToString:#"pdf"]) {
[driveFiles addObject:file];
}
}
}
}
And GTLDriveFile pass the object that you have in the array
GTLDriveFile *file=[driveFiles objectAtIndex:indexPath.row];
This is the code for download the file
NSString *link;
if (file.webContentLink) {
link = file.webContentLink;
} else if (file.embedLink) {
link = file.embedLink;
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"ERROR" message:#"File has no downloadable link" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
if (link) {
NSString *downloadUrl = file.downloadUrl;
GTMHTTPFetcher *fetcher = [self.driveService.fetcherService fetcherWithURLString:downloadUrl];
//async call to download the file data
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
if (data) {
NSString *dirPath = [self directoryPathForSavingFile];
NSString *filePath = [dirPath stringByAppendingPathComponent:file.title];
[self saveFileJSONData:data forFileName:filePath withCompletionHandler:^(BOOL successStatus) {
// Adding skip attribute to avoid data sinking in iCloud
BOOL path = [[NSFileManager defaultManager] fileExistsAtPath:filePath];
if (path) {
NSLog(#"filePath %#", filePath);
}
}];
}
} else {
NSLog(#"An error occurred: %#", error);
}
}];
}
Code for Directory path for save the file
- (NSString *)directoryPathForSavingFile:(NSString *)directoryName {
NSString *applicationDirectory = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
applicationDirectory = [applicationDirectory stringByAppendingPathComponent:directoryName];
return applicationDirectory;
}
I'm using SCShareViewController from SoundCloud API in my project (iOS 7.0) so that the user can share your audio on SoundCloud AND on Facebook through the SoundCloud UI.
The upload in SoundCloud is working perfectly! But the share on facebook is not working =/
Does anyone can help me with this?
Is it necessary for me to create an app on facebook? Or does it already use SoundCloud's instead?
EDIT:
Here is my code:
NSURL *trackURL = [NSURL fileURLWithPath:trackPath];
SCShareViewController *shareViewController;
shareViewController = [SCShareViewController shareViewControllerWithFileURL:trackURL
completionHandler:^(NSDictionary *trackInfo, NSError *error){
if (SC_CANCELED(error)) {
NSLog(#"Canceled!");
} else if (error) {
NSLog(#"Ooops, something went wrong: %#", [error localizedDescription]);
} else {
NSLog(#"Uploaded track: %#", trackInfo);
}
}];
[self presentModalViewController:shareViewController animated:YES];
I'm using writeImageToSavedPhotosAlbum:orientation:completionBlock: to save an image and it's ok. Then I want an array of assets in the Album.
The first time I refresh my array it doesn't count the new image, while calling it a second time it works fine.
Why? I understand that the writeImageToSavedPhotosAlbum start another thread and that the Block is called after the save operation completes, isn't it?
This is the code I use to save the image and refresh my array:
[_album refresh];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:image
metadata:metadataAsMutable
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(#"ERROR: the image failed to be written");
}
else {
NSLog(#"PHOTO SAVED - assetURL: %#", assetURL);
}
[_album refresh];
[_album refresh];
[spinner stopAnimating];
[self close];
}];
This is the refresh function:
- (void)refresh {
[_imgAssets removeAllObjects];
if (_albumGroup) {
[_albumGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result == nil) {
NSLog(#"done enumerating photos (%d)", [_imgAssets count]);
return;
}
[_imgAssets addObject:result];
//NSLog(#">> enumerating photos (%d)", [_imgAssets count]);
}];
}
}
And this is what I obtain:
2013-06-04 23:19:07.962 PhotInfo[4835:c07] done enumerating photos (29)
2013-06-04 23:19:08.041 PhotInfo[4835:c07] PHOTO SAVED - assetURL: assets-library://asset/asset.JPG?id=CDC2E97A-FF47-4A52-99E2-574037155D92&ext=JPG
2013-06-04 23:19:08.042 PhotInfo[4835:c07] done enumerating photos (29)
2013-06-04 23:19:08.044 PhotInfo[4835:c07] done enumerating photos (30)
Moreover, if I replace the second of the 3 refresh with
[_album performSelectorOnMainThread:#selector(refresh) withObject:nil waitUntilDone:YES];
it may or may not read the added image.
Where is the problem?
Thanks for the help.
I've resolved setting an observer on ALAssetsLibraryChangedNotification.