How to Upload & Retrive folder to appDataFolder inside Google Driver IOS App - ios

How to upload folder on appDataFolder of Google Drive , I am trying to below code , but not work proper. so, can any buddy please help me regarding uploading folder in Google Drive from IOS App.
GTLServiceDrive *drive= [self driveService];
GTLDriveFile *folder = [GTLDriveFile object];
folder.mimeType = #"application/vnd.google-apps.folder";
folder.parents = #[appDataFolder];
GTLUploadParameters *uploadParameters = [GTLUploadParameters
uploadParametersWithData:data
MIMEType:#"application/vnd.google-apps.folder"];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesCreateWithObject:folder uploadParameters:uploadParameters];
//query.q = [NSString stringWithFormat:#"appDataFolder"];
[drive executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error) {
if (error == nil) {
} else {
}
}];

You need to set the Parents property of your driveFile
GTLDriveParentReference *parentRef = [GTLDriveParentReference object];
parentRef.identifier = folderIdentifier; // identifier property of the folder
driveFile.parents = #[ parentRef ];

Related

How to Implement Map Places autocomplete in Baidu Map for IOS SDK

This is my first time that I am using Baidu API. I am having problem implementing Baidu places auto-complete API in my project. I am using the Baidu developers link to http://lbsyun.baidu.com/index.php?title=iossdk.
someone please give me to some tutorial in this regard?
i am following this tutorial. link
but in this tutorial i can not receive json file, give me a error
{ "Status": 102, "message": "MCODE parameter is not present, mobile
type mcode required parameter"}
Seems you should use the POI Search module of BaiduMapKit.Try this.
BMKCitySearchOption *citySearchOption = [[BMKCitySearchOption alloc]init];
citySearchOption.pageIndex = curPage;//here is the page index , you can set it to 0
citySearchOption.pageCapacity = 10;
citySearchOption.city= #"上海";//here is the city where you want to search the road
citySearchOption.keyword = #"淮海路";//here is the road name or someplace name you want to search
BOOL flag = [_poisearch poiSearchInCity:citySearchOption];
if(flag) {
_nextPageButton.enabled = true;
NSLog(#"success");
}
else {
_nextPageButton.enabled = false;
NSLog(#"fail");
}
Implement AutoComplete In Baidu Map using Baidu Web API
- (void)viewDidLoad {
BaseString = #"http://api.map.baidu.com/place/v2/suggestion?query=";
ak = #"56dIEtBAp1CU7u8ZMcq8DyUH2mVsn38x"; mcode = #"com.baidu.Baidu-Map-Demo";
regionkey = #"中国";
PathString = #"http://api.map.baidu.com/direction/v2/transit?origin=";
self .mapView .userTrackingMode = BMKUserTrackingModeFollow;
// 2. Set the map type self.mapView.mapType = BMKMapTypeStandard;
// 3. Set Agent self.mapView.delegate = self;
[super viewDidLoad];
mapView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
mapView.delegate = self; anotation = [[BMKPointAnnotation alloc]init];
destination = [[BMKPointAnnotation alloc]init];
PathUrl = [[NSURL alloc]init];
finalPathArray = [[NSMutableArray alloc]init];
session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
downloadURL = [[NSURL alloc]init];
path = [[BMKPolyline alloc]init];
flag = 0;
}
-(void)GetSuggestion: (NSString *)query {
NSString *stringUrl = [NSString stringWithFormat:#"%#%#&page_size=10&page_num=0&scope=1&region=%#&output=json&ak=%#&mcode=%#",BaseString,query,regionkey,ak,mcode]; stringUrl = [stringUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
downloadURL = [NSURL URLWithString:stringUrl];
if (downloadURL != nil) {
if (DownloadTask != nil) {
[DownloadTask suspend];
}
DownloadTask = [session dataTaskWithURL:downloadURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *AutocompleteData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
resultArray = AutocompleteData[#"result"];
tbl_result.hidden = NO;
[tbl_result reloadData];
}];
[DownloadTask resume];
}
}
MCODE parameter means your bundle id must spacify bundle id with urlFor example write url for autocomplete FOR Autocomplete use this function

iOS Share Extension unable to get shared URL from Chrome

I am trying to implement share extension for my app. Its working good in safari browser and youtube app (i.e) when i share from these apps i get the public.url which is the url to be shared.
When i tried the same in chrome it was not showing the extension. When i added the NSExtensionActivationSupportsText under the NSExtensionActivationRule to true its started showing. But when i try to share the contents i am unable to fetch the URL String which is to be shared. I get only contentText.
I have followed the approach shown in this link https://stackoverflow.com/a/31942744/6199038.
I have also added the demoProcessor.js
var MyPreprocessor = function() {};
MyPreprocessor.prototype = {
run: function(arguments) {
arguments.completionFunction({"URL": document.URL, "pageSource": document.documentElement.outerHTML, "title": document.title, "selection": window.getSelection().toString()});
}
};
var ExtensionPreprocessingJS = new MyPreprocessor;
I am using SLComposeServiceViewController
In my ShareViewController.m i am trying to get the data as shown below,
for safari i used this which is working fine
NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
NSItemProvider *itemProvider = [[item.userInfo valueForKey:NSExtensionItemAttachmentsKey] objectAtIndex:0];
if ([itemProvider hasItemConformingToTypeIdentifier:#"public.url"]) {
[itemProvider loadItemForTypeIdentifier:#"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
urlString = url.absoluteString;
NSLog(#"urlString %#",urlString);
}];
}
Then i modified my code to this to get the URL from chrome, Which is not working.
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypePropertyList]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypePropertyList options:nil completionHandler:^(NSDictionary *jsDict, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary *jsPreprocessingResults = jsDict[NSExtensionJavaScriptPreprocessingResultsKey];
NSString *selectedText = jsPreprocessingResults[#"selection"];
NSString *pageTitle = jsPreprocessingResults[#"title"];
NSString *URL = jsPreprocessingResults[#"URL"];
NSLog(#"selectedText %#",selectedText);
NSLog(#"pageTitle %#",pageTitle);
NSLog(#"URL %#",URL);
});
}];
break;
}
}
}
PLEASE ADVICE
I have solved it myself. As it was not entering inside the "loadItemForTypeIdentifier" method. So i had modified my method to the below code
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
NSString *URLinPlainText = [item.attributedContentText string];
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) {
urlString = url.absoluteString;
NSLog(#"<< URL >> %#",urlString);
return;
}];
}
else if (URLinPlainText) {
// In Some app i got the URL in a Plain text mode
if([URLinPlainText containsString:#"http"]){
urlString = [sharedPlainText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(#"<< URL >> %#",urlString);
return;
}
}
}
}
And also i have removed the demoProcessor.js.
Now i am able to get the URL from almost all the News Apps, Browsers like (Chrome, firefox, safari) and in some of the apps i am getting the shared url in the form of plain text which is then i had to remove the empty spaces and convert it to NSString.
According to my understanding the demoprocessor.js is used if user wants to access the url page properties for ex(title, baseURL, og:image, og:description etc...) which works only for safari browser.

Issue with uploading a JPEG, Google Drive saves it as a PNG

I'm having an issue with uploading a photo to Google Drive via the SDK made available for Objective-C.
The summary of the situation is the following, I create a folder with a defined name, after the folder is created I upload a finite number of photos stores in my app. I wait until I receive confirmation that a photo was uploaded successfully before trying the next one on the list.
The issue I'm having is the following, I know the photo file is ~9MB, and it hits Google Drive successfully. The problem is that I'm uploading it with a MIME type image/jpeg, the file that actually appears in Google Drive is a PNG image file, and it's 22 MB in size!!!!!!! I can't understand why it's interpreting it as a PNG, and why does the size grow so much.
This is my relevant code:
- (void) uploadPhotoToFolder:(NSString *)identifier withIndex:(int)index{
UIImage *content = [[photoArray objectAtIndex:index] objectAtIndex:0];
NSString *mimeType = #"image/jpeg";
GTLDriveFile *metadata = [GTLDriveFile object];
NSString *name =#"FileName";
metadata.name = name;
metadata.parents = #[identifier];
NSData *data = UIImagePNGRepresentation(content);
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data
MIMEType:mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesCreateWithObject:metadata
uploadParameters:uploadParameters];
[self.service executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *updatedFile,
NSError *error) {
if (error == nil) {
//Notify that upload was successful
}
else {
//Notify that upload failed.
}
}];
}
Thank you in advance for any help.
You're using NSData *data = UIImagePNGRepresentation(content); which makes your image a PNG despite the MIME type you send.

Uploading images on Google Drive from IOS Application in Specific Folder provided from the User

I am working with an iOS application in which i have to upload images on Google Drive from my IOS Application.
I am working with the below code,but not getting my image insert in the specific folder.
- (void)uploadPhoto:(UIImage*)image
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"];
GTLDriveFile *file = [GTLDriveFile object];
file.title = [dateFormat stringFromDate:[NSDate date]];
file.descriptionProperty = #"Uploaded from the Google Drive iOS Quickstart";
file.mimeType = #"image/png";
NSData *data = UIImagePNGRepresentation((UIImage *)image);
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
uploadParameters:uploadParameters];
GTLDriveParentReference *parentReference = [GTLDriveParentReference object];
// parentReference.identifier = #"root";
parentReference.identifier = [NSString stringWithFormat:#"root%#",albumNAME];
file.parents = #[parentReference];
UIAlertView *waitIndicator = [self showWaitIndicator:#"Uploading to Google Drive"];
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLDriveFile *insertedFile, NSError *error) {
[waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
if (error == nil)
{
NSLog(#"File ID: %#", insertedFile.identifier);
[self showAlert:#"Google Drive" message:#"File saved!"];
}
else
{
NSLog(#"An error occurred: %#", error);
[self showAlert:#"Google Drive" message:#"Sorry, an error occurred!"];
}
}];
}
albumNAME is the name of specific folder in which i have to insert the image on google drive.
Please help me out from this problem.
GTLDriveParentReference.identifier should be the ID of the folder, not it's name. You must first find or create the folder, then use the ID of that folder here.

Google Objective c api : completionHandler never called when there is no internet connection

iOS beginner, I am trying to upload videos on youtube using the google objective c api.
In most cases, it just works. Videos can be uploaded and my callback receives errors if they occur.
But if I turn off the internet connection on the device, the callback is never called. (even though it is called for other types of errors, like incorrect title or incorrect tags)
My personal guess it that while I have set a callback for GTLServiceYouTube, I haven't explicitly set one for GTMOAuth2Authentication, hence the absence of a call. But I am not sure how to set one and found nothing about it anywhere.
Note that in my situation, I really need my users to be able to upload a video without having to enter their credentials, hence the manual initialization of the GTMOAuth2Authentication.
Here is my code, please tell me if I am doing something wrong and how I could fix it.
NSString *clientID = #"185815387242-hqo2d4e06j4hk4f02t5gvn7jcifakdvr.apps.googleusercontent.com";
NSString *clientSecret = #"2LKi7orHyphJXXXXXXXXXXXX";
NSURL *tokenURL = [NSURL URLWithString:#"https://accounts.google.com/o/oauth2/token"];
NSString *redirectURI = #"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:kGTMOAuth2ServiceProviderGoogle
tokenURL:tokenURL
redirectURI:redirectURI
clientID:clientID
clientSecret:clientSecret];
[auth setKeysForResponseString:#"email=annonce-video-i-6620%40pages.plusgoogle.com&isVerified=1&refresh_token=1%2FFFo5rlNs51u9g2TpCIE2oji_ACvDPc0XXXXXXXXXXXX&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&serviceProvider=Google&userID=107586507912247324352"];
//////////////////////////////////////////////////
GTLServiceYouTube *youTubeService = [[GTLServiceYouTube alloc] init];
// Have the service object set tickets to fetch consecutive pages
// of the feed so we do not need to manually fetch them.
youTubeService.shouldFetchNextPages = YES;
// Have the service object set tickets to retry temporary error conditions
// automatically.
youTubeService.retryEnabled = YES;
youTubeService.authorizer = auth;
// Status.
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus object];
// Snippet.
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title = #"TITLE";
NSString *desc = #"DESC";
if ([desc length] > 0) {
snippet.descriptionProperty = desc;
}
NSString *tagsStr = #"TAGS";
if ([tagsStr length] > 0) {
snippet.tags = [tagsStr componentsSeparatedByString:#","];
}
GTLYouTubeVideo *video = [GTLYouTubeVideo object];
video.status = status;
video.snippet = snippet;
// Get a file handle for the upload data.
NSString *path = #"AVALIDPATH";
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
if (fileHandle) {
NSString *mimeType = #"video/mp4";
GTLUploadParameters *uploadParameters =
[GTLUploadParameters uploadParametersWithFileHandle:fileHandle
MIMEType:mimeType];
uploadParameters.uploadLocationURL = nil;
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:video
part:#"snippet,status"
uploadParameters:uploadParameters];
GTLServiceYouTube *service = youTubeService;
[service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubeVideo *uploadedVideo,
NSError *error) {
//NEVER CALLED WHEN THE DEVICE IS IN AIRPLANE MODE
NSLog(#"And call me maybe.");
}];
I have traced back the absence of call to GTMHTTPFetcher line 969
#synchronized(self) {
target = [[delegate_ retain] autorelease];
sel = finishedSel_;
#if NS_BLOCKS_AVAILABLE
block = [[completionBlock_ retain] autorelease];
#endif
}
The synchronized block is called twice, once to call the GTMOAuth2Authentication callback, and a second time to call... Well... nil
A bug in retry handling on uploads was recently fixed in the library. Try updating your Google API library sources.

Resources