2014-06-06 4 views
10
साथ

किसी को भी एक स्विफ्ट परियोजनागूगल ऑब्जेक्टिव-सी एपीआई 'जीटीएल' स्विफ्ट

https://developers.google.com/drive/ios/quickstart

मैं अलग तरीके का एक संख्या की कोशिश की है, लेकिन नहीं मिल सकता है में Google डिस्क API (Objjective सी) का उपयोग में सफल रही है यह संकलित करने के लिए

मैं सबसे नज़दीकी लिंक नीचे दिए गए लिंक में रॉब की पद्धति का उपयोग कर रहा था और ब्रिजिंगहेडर को #import "GTLDrive.h" जोड़ रहा था। इसने मुझे जीटीएलडीआरआईव बनाने की इजाजत दी, लेकिन ऑथ becauser नहीं, मैं एआरसी झंडे पर ध्यान देने के लिए एक्सकोड नहीं मिला।

Stackoverflow 11370752

+0

hii @Ryan Heitner यू तेज में गूगल कैलेंडर लागू किया है https://github.com/goktugyil/QorumLogs

यहाँ यह सेट करने के तरीके के ट्यूटोरियल है –

उत्तर

14

मैं अंत में

Stack OverFlow 11370752

निम्नलिखित और

#import "GTLDrive.h" 
#import "GTMOAuth2ViewControllerTouch.h" 

साथ एक ब्रिजिंग-header.h फ़ाइल जोड़ने किसी समय मैं शामिल बचाने के लिए कर ऐसा करते हैं करने में कामयाब मेरी उद्देश्य-सी स्विफ्ट Google क्विकस्टार्ट

में शामिल नमूने का अनुवाद

IOS Quickstart for Google Drive

import UIKit 
import MobileCoreServices 

class ViewController: UIViewController , UINavigationControllerDelegate ,UIImagePickerControllerDelegate { 
var window: UIWindow? 
let driveService : GTLServiceDrive = GTLServiceDrive() 

let kKeychainItemName : NSString = "Google Drive Quickstart" 
let kClientID : NSString = "Your Client ID" 
let kClientSecret : NSString = "Your Secret" 

func showWaitIndicator(title:String) -> UIAlertView { 
    //  println("showWaitIndicator \(title)") 
    var progressAlert = UIAlertView() 
    progressAlert.title = title 
    progressAlert.message = "Please Wait...." 
    progressAlert.show() 

    let activityView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White) 
    activityView.center = CGPointMake(progressAlert.bounds.size.width/2, progressAlert.bounds.size.height - 45) 
    progressAlert.addSubview(activityView) 
    activityView.hidesWhenStopped = true 
    activityView.startAnimating() 
    return progressAlert 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.driveService.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(kKeychainItemName, 
     clientID: kClientID, 
     clientSecret: kClientSecret) 
} 

override func viewDidAppear(animated: Bool) { 
    self.showCamera() 
} 


func showCamera() { 
    var cameraUI = UIImagePickerController() 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) { 
     cameraUI.sourceType = UIImagePickerControllerSourceType.Camera 
    } else { 
     cameraUI.sourceType = UIImagePickerControllerSourceType.PhotoLibrary 
     if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad { 
      self.showAlert("Error", message: "Ipad Simulator not supported") 
      return 
     } 
    } 

    cameraUI.mediaTypes = [kUTTypeImage as String] 
    cameraUI.allowsEditing = true 
    cameraUI.delegate = self 
    self.presentModalViewController(cameraUI, animated: true) 
    println("Show Camera \(self.isAuthorized())") 
    if (!self.isAuthorized()) 
    { 
     // Not yet authorized, request authorization and push the login UI onto the navigation stack. 
     cameraUI.pushViewController(self.createAuthController(), animated:true); 
    } 
} 
// Handle selection of an image 
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info:NSDictionary) { 
    println("imagePickerController didFinishPickingMediaWithInfo") 
    let image = info.valueForKey(UIImagePickerControllerOriginalImage) as UIImage 
    self.dismissModalViewControllerAnimated(true) 
    self.uploadPhoto(image) 

} 

// Handle cancel from image picker/camera. 

func imagePickerControllerDidCancel(picker: UIImagePickerController){ 
    self.dismissModalViewControllerAnimated(true) 
} 

// Helper to check if user is authorized 
func isAuthorized() -> Bool { 
    return (self.driveService.authorizer as GTMOAuth2Authentication).canAuthorize 
} 

// Creates the auth controller for authorizing access to Google Drive. 
func createAuthController() -> GTMOAuth2ViewControllerTouch { 
    return GTMOAuth2ViewControllerTouch(scope: kGTLAuthScopeDriveFile, 
     clientID: kClientID, 
     clientSecret: kClientSecret, 
     keychainItemName: kKeychainItemName, 
     delegate: self, 
     finishedSelector: Selector("viewController:finishedWithAuth:error:")) 

} 
//  “func join(string s1: String, toString s2: String, withJoiner joiner: String)” 

// Handle completion of the authorization process, and updates the Drive service 
// with the new credentials. 
func viewController(viewController: GTMOAuth2ViewControllerTouch , finishedWithAuth authResult: GTMOAuth2Authentication , error:NSError) { 
    if error != nil 
    { 
     self.showAlert("Authentication Error", message:error.localizedDescription) 
     self.driveService.authorizer = nil 
    } else { 
     println("Authentication success") 
     self.driveService.authorizer = authResult 
    } 

} 


// Uploads a photo to Google Drive 
func uploadPhoto(image: UIImage) { 
    println("uploading Photo") 
    let dateFormat = NSDateFormatter() 
    dateFormat.dateFormat = "'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')" 

    let file = GTLDriveFile.object() as GTLDriveFile 
    file.title = dateFormat.stringFromDate(NSDate()) 
    file.descriptionProperty = "Uploaded from Google Drive IOS" 
    file.mimeType = "image/png" 

    let data = UIImagePNGRepresentation(image) 
    let uploadParameters = GTLUploadParameters(data: data, MIMEType: file.mimeType) 
    let query = GTLQueryDrive.queryForFilesInsertWithObject(file, uploadParameters: uploadParameters) as GTLQueryDrive 
    let waitIndicator = self.showWaitIndicator("Uploading To Google Drive") 
    //  self.driveService.executeQuery(query, completionHandler: {(ticket: GTLServiceTicket, insertedFile: AnyObject, error: NSError) in { 
    // 
    // 
    //  } 
    // elf.driveService.executeQuery(<#query: GTLQueryProtocol?#>, completionHandler: <#((GTLServiceTicket!, AnyObject!, NSError!) -> Void)?#>) 
    self.driveService.executeQuery(query, completionHandler: { (ticket, insertedFile , error) -> Void in 
     let myFile = insertedFile as? GTLDriveFile 

     waitIndicator.dismissWithClickedButtonIndex(0, animated: true) 
     if error == nil { 
      println("File ID \(myFile?.identifier)") 
      self.showAlert("Google Drive", message: "File Saved") 
     } else { 
      println("An Error Occurred! \(error)") 
      self.showAlert("Google Drive", message: "Sorry, an error occurred!") 
     } 

     }) 
} 

func showAlert(title: String, message: String) { 
    let cancel = "OK" 
    println("show Alert") 
    let alert = UIAlertView() 
    alert.title = title 
    alert.message = message 
    alert.addButtonWithTitle(cancel) 
    alert.show() 
} 

} 
1

बेहतर उसके बाद इस link उल्लेख आप लागू कर सकते हैं iPhone परियोजना के लिए गूगल ऑब्जेक्टिव-सी एपीआई 'जीटीएल' जोड़ने के लिए Pod उपयोग करने के लिए @Ryan Heitner का जवाब

1

नहीं वास्तव में एक जवाब इस सवाल के लिए, लेकिन इस रेपो में मैंने Google के एपीआई का उपयोग किये बिना आईओएस ऐप से Google फॉर्म का उपयोग किया। https://github.com/goktugyil/QorumLogs/blob/master/Log%20To%20GoogleDocs.md

यहाँ यह करने के लिए कोड:

private static var googleFormLink: String! 
private static var googleFormAppVersionField: String! 
private static var googleFormUserInfoField: String! 
private static var googleFormMethodInfoField: String! 
private static var googleFormErrorTextField: String! 

/// Setup Google Form links 
static func setupOnlineLogs(#formLink: String, versionField: String, userInfoField: String, methodInfoField: String, textField: String) { 
    googleFormLink = formLink 
    googleFormAppVersionField = versionField 
    googleFormUserInfoField = userInfoField 
    googleFormMethodInfoField = methodInfoField 
    googleFormErrorTextField = textField 
} 

private static func sendError(#text: String) { 
    var url = NSURL(string: googleFormLink) 
    var postData = googleFormAppVersionField + "=" + text 
    postData += "&" + googleFormUserInfoField + "=" + "anothertext"   
    postData += "&" + googleFormMethodInfoField + "=" + "anothertext" 
    postData += "&" + googleFormErrorTextField + "=" + "anothertext" 

    var request = NSMutableURLRequest(URL: url!) 
    request.HTTPMethod = "POST" 
    request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type") 
    request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding) 
    var connection = NSURLConnection(request: request, delegate: nil, startImmediately: true) 

} 
संबंधित मुद्दे