ड्राइवर SDK टूल एक लाइब्रेरी है, जिसे ड्राइवर ऐप्लिकेशन के साथ इंटिग्रेट किया जा सकता है. हां फ़्लीट इंजन को ड्राइवर की जगह, रास्ते की जानकारी, दूरी और ETA. यह नेविगेशन SDK टूल के साथ भी काम करता है, यह ड्राइवर के लिए मोड़-दर-मोड़ रास्ते की जानकारी देता है.
सिस्टम में कम से कम यह कॉन्फ़िगरेशन होना चाहिए
ज़रूरी शर्तें
इस गाइड में यह माना गया है कि आपका ऐप्लिकेशन नेविगेशन SDK टूल और फ़्लीट इंजन बैकएंड सेट अप हो गया है और उपलब्ध है. हालांकि, उदाहरण कोड में सैंपल के तौर पर, नेविगेशन SDK टूल.
आपको iOS के लिए Maps SDK टूल भी चालू करना होगा और एपीआई पासकोड पाएं.
ऐक्सेस पाएं
अगर आप Google Workspace के ग्राहक हैं, तो
Workspace ग्रुप, जैसे कि
ऑनबोर्डिंग के दौरान और google-maps-platform-sdk-users@workspacedomain.com
Google को वह नाम दें. यह सुझाया गया तरीका है.
इसके बाद, आपका Workspace ग्रुप, अनुमति वाली सूची में शामिल हो जाएगा
CocoaPods का डेटा स्टोर करने की सही जगह का ऐक्सेस देता है. पुष्टि करें कि उपयोगकर्ता
जिन ईमेल और सेवा खाते के ईमेल को ऐक्सेस करने की ज़रूरत है वे इस सूची में शामिल हैं.
अगर आपके संगठन को Workspace ग्रुप नहीं बनाए जा सकते, तो Google को उन ग्रुप की सूची भेजें उन उपयोगकर्ता और सेवा खाते के ईमेल पते हैं जिन्हें इन आर्टफ़ैक्ट का ऐक्सेस चाहिए.
लोकल डेवलपमेंट
लोकल डेवलपमेंट के लिए, Cloud SDK टूल.
gcloud
gcloud auth login
लॉग इन करने के लिए इस्तेमाल किया जाने वाला ईमेल पता, Workspace ग्रुप का सदस्य होना चाहिए.
ऑटोमेशन (सिस्टम बनाना या लगातार इंटिग्रेशन करना)
ऑटोमेशन होस्ट को इसके हिसाब से सेट अप करना सबसे सही तरीके:
अगर आपकी प्रोसेस Google Cloud के एनवायरमेंट में चलती है, तो इसका इस्तेमाल करें ऑटोमैटिक क्रेडेंशियल की पहचान करें.
अगर ऐसा नहीं है, तो सेवा खाते की कुंजी वाली फ़ाइल को होस्ट का फ़ाइल-सिस्टम है और GOOGLE_APPLICATION_CREDENTIALS एनवायरमेंट वैरिएबल में सही तरीके से बदलाव किया हो.
क्रेडेंशियल से जुड़े सेवा खाते का ईमेल पता, शामिल हैं.
प्रोजेक्ट कॉन्फ़िगरेशन
CocoaPods का इस्तेमाल करके ड्राइवर SDK टूल को कॉन्फ़िगर किया जा सकता है.
CocoaPods का इस्तेमाल करें
CocoaPods का इस्तेमाल करके ड्राइवर SDK टूल को कॉन्फ़िगर करने के लिए, आपको इन आइटम की ज़रूरत होगी:
- CocoaPods टूल: इस टूल को इंस्टॉल करने के लिए, Terminal खोलें और
आदेश दिखाई देगा.
shell sudo gem install cocoapods
देखें CocoaPods के इस्तेमाल के लिए शुरुआती निर्देश देखें.
ड्राइवर SDK टूल के लिए एक Podfile बनाएं और एपीआई और उसकी डिपेंडेंसी: अपने प्रोजेक्ट में Podfile नाम की एक फ़ाइल बनाएं डायरेक्ट्री. यह फ़ाइल आपके प्रोजेक्ट की डिपेंडेंसी के बारे में बताती है. Podfile में बदलाव करें और अपनी डिपेंडेंसी जोड़ें. यहां एक उदाहरण दिया गया है, जिसमें डिपेंडेंसी:
source "https://github.com/CocoaPods/Specs.git" target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pod 'GoogleRidesharingDriver' end
Podfile को सेव करें. टर्मिनल खोलें और उस डायरेक्ट्री पर जाएं जिसमें पॉडफ़ाइल:
cd <path-to-project>
पॉड इंस्टॉल करने का निर्देश चलाएं. इससे साथ ही, Podfile भी शामिल करें.
pod install
Xcode बंद करें और फिर अपने प्रोजेक्ट की .xcworkspace फ़ाइल खोलें (दो बार क्लिक करें) Xcode लॉन्च करने के लिए. आगे से, आपको .xcworkspace फ़ाइल का इस्तेमाल करना होगा प्रोजेक्ट को खोलने के लिए.
SDK टूल के ऐल्फ़ा/बीटा वर्शन
iOS के लिए ड्राइवर SDK टूल के अल्फ़ा या बीटा वर्शन कॉन्फ़िगर करने के लिए आपको इनकी ज़रूरत होगी आइटम:
CocoaPods टूल: इस टूल को इंस्टॉल करने के लिए, Terminal खोलें और आदेश दिखाई देगा.
sudo gem install cocoapods
देखें CocoaPods के इस्तेमाल के लिए शुरुआती निर्देश देखें.
Google ऐक्सेस सूची में आपका डेवलपमेंट खाता. पॉड रिपॉज़िटरी के ऐल्फ़ा और बीटा वर्शन सार्वजनिक सोर्स नहीं हैं. यहां की यात्रा पर हूं उन वर्शन को ऐक्सेस करने के लिए, Google ग्राहक इंजीनियर से संपर्क करें. इंजीनियर, आपके डेवलपमेंट खाते को ऐक्सेस सूची में जोड़ता है और इसके लिए कुकी सेट करता है पुष्टि करने के लिए.
ऐक्सेस लिस्ट में अपने प्रोजेक्ट के शामिल होने के बाद, पॉड को ऐक्सेस किया जा सकता है.
iOS के लिए ड्राइवर SDK टूल के लिए एक Podfile बनाएं और एपीआई और उसकी डिपेंडेंसी: अपने प्रोजेक्ट में Podfile नाम की एक फ़ाइल बनाएं डायरेक्ट्री. यह फ़ाइल आपके प्रोजेक्ट की डिपेंडेंसी के बारे में बताती है. Podfile में बदलाव करें और अपनी डिपेंडेंसी जोड़ें. यहां एक उदाहरण दिया गया है, जिसमें डिपेंडेंसी:
source "https://cpdc-eap.googlesource.com/ridesharing-driver-sdk.git" source "https://github.com/CocoaPods/Specs.git" target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pod 'GoogleRidesharingDriver' end
Podfile को सेव करें. टर्मिनल खोलें और उस डायरेक्ट्री पर जाएं जिसमें पॉडफ़ाइल:
cd <path-to-project>
पॉड इंस्टॉल करने का निर्देश चलाएं. इससे साथ ही, Podfile भी शामिल करें.
pod install
Xcode बंद करें और फिर अपने प्रोजेक्ट की .xcworkspace फ़ाइल खोलें (दो बार क्लिक करें) Xcode लॉन्च करने के लिए. आगे से, आपको .xcworkspace फ़ाइल का इस्तेमाल करना होगा प्रोजेक्ट को खोलने के लिए.
XCFramework इंस्टॉल करना
XCFramework एक बाइनरी पैकेज होता है, जिसका इस्तेमाल ड्राइवर SDK टूल को इंस्टॉल करने के लिए किया जाता है. इस पैकेज का इस्तेमाल कई प्लैटफ़ॉर्म पर किया जा सकता है. इनमें M1 चिपसेट का इस्तेमाल करने वाली मशीनें भी शामिल हैं. इस गाइड में, ड्राइवर SDK टूल वाले XCFramework को मैन्युअल तरीके से अपने प्रोजेक्ट में जोड़ने और Xcode में बिल्ड सेटिंग कॉन्फ़िगर करने का तरीका बताया गया है.
SDK टूल बाइनरी और संसाधन डाउनलोड करें:
XCFramework और संसाधनों को ऐक्सेस करने के लिए, ज़िप की गई फ़ाइलों को अनपैक करें.
Xcode शुरू करें और या तो कोई मौजूदा प्रोजेक्ट खोलें या एक नया प्रोजेक्ट बनाएं. अगर आपने iOS का इस्तेमाल पहले कभी नहीं किया है, तो नया प्रोजेक्ट बनाएं और iOS ऐप्लिकेशन टेंप्लेट चुनें.
अगर आपके प्रोजेक्ट ग्रुप में फ़्रेमवर्क पहले से मौजूद नहीं है, तो एक ग्रुप बनाएं.
डाउनलोड की गई
gRPCCertificates.bundle
फ़ाइल को खींचकर, अपने Xcode प्रोजेक्ट की टॉप लेवल डायरेक्ट्री में छोड़ें. जब कहा जाए, तब 'आइटम कॉपी करें' को चुनें.ड्राइवर SDK टूल इंस्टॉल करने के लिए,
GoogleRidesharingDriver.xcframework
फ़ाइल को फ़्रेमवर्क, लाइब्रेरी, और एम्बेड किए गए कॉन्टेंट में जाकर अपने प्रोजेक्ट में खींचें और छोड़ें. जब कहा जाए, तब 'आइटम कॉपी करें' को चुनें.डाउनलोड किए गए
GoogleRidesharingDriver.bundle
को अपने Xcode प्रोजेक्ट की टॉप लेवल डायरेक्ट्री में खींचें और छोड़ें. जब कहा जाए, तबCopy items if needed
चुनें.प्रोजेक्ट नेविगेटर से अपना प्रोजेक्ट चुनें और अपने ऐप्लिकेशन का टारगेट चुनें.
बिल्ड के चरण टैब खोलें और अगर ये फ़्रेमवर्क और लाइब्रेरी पहले से मौजूद नहीं हैं, तो उन्हें लाइब्रेरी के साथ लिंक बाइनरी को जोड़ें:
Accelerate.framework
AudioToolbox.framework
AVFoundation.framework
CoreData.framework
CoreGraphics.framework
CoreLocation.framework
CoreTelephony.framework
CoreText.framework
GLKit.framework
ImageIO.framework
libc++.tbd
libxml2.tbd
libz.tbd
LocalAuthentication.framework
OpenGLES.framework
QuartzCore.framework
SystemConfiguration.framework
UIKit.framework
WebKit.framework
किसी खास टारगेट के बजाय, अपना प्रोजेक्ट चुनें और बिल्ड सेटिंग टैब खोलें. अन्य लिंकर फ़्लैग सेक्शन में, डीबग और रिलीज़, दोनों के लिए
‑ObjC
जोड़ें. अगर ये सेटिंग नहीं दिख रही हैं, तो बिल्ड सेटिंग बार में फ़िल्टर को बुनियादी से सभी में बदलें.
Apple की निजता मेनिफ़ेस्ट फ़ाइल की जांच करें
Apple को App Store पर मौजूद ऐप्लिकेशन के लिए, ऐप्लिकेशन की निजता से जुड़ी जानकारी की ज़रूरत होती है. अपडेट और ज़्यादा जानकारी के लिए, Apple App Store के निजता से जुड़ी जानकारी वाले पेज पर जाएं.
Apple Privacy मेनिफ़ेस्ट फ़ाइल, SDK टूल के लिए संसाधनों के बंडल में शामिल होती है. यह पुष्टि करने के लिए कि निजता मेनिफ़ेस्ट फ़ाइल शामिल की गई है और इसके कॉन्टेंट की जांच करने के लिए, अपने ऐप्लिकेशन का संग्रह बनाएं और संग्रह से निजता रिपोर्ट जनरेट करें.
अनुमति देने और पुष्टि करने की प्रोसेस लागू करें
जब आपका ड्राइवर ऐप्लिकेशन, Fleet Engine बैकएंड को अपडेट जनरेट करके भेजता है, तो
अनुरोध में मान्य ऐक्सेस टोकन शामिल होने चाहिए. अधिकृत करने और
इन अनुरोधों की पुष्टि करने के बाद, ड्राइवर SDK टूल आपके ऑब्जेक्ट को
GMTDAuthorization
प्रोटोकॉल का इस्तेमाल करना चाहिए. ऑब्जेक्ट, ज़रूरी ऐक्सेस टोकन देने के लिए ज़िम्मेदार है.
ऐप्लिकेशन डेवलपर के तौर पर, आपको यह चुनना होता है कि टोकन कैसे जनरेट किए जाएं. लागू किया गया के तहत ये काम किए जा सकते हैं:
- किसी एचटीटीपीएस सर्वर से ऐक्सेस टोकन फ़ेच करें. हो सकता है कि यह JSON फ़ॉर्मैट में हो.
- टोकन को पार्स और कैश मेमोरी में सेव करें.
- टोकन की समयसीमा खत्म होने पर उसे रीफ़्रेश करें.
फ़्लीट इंजन सर्वर से मिलने वाले टोकन की जानकारी के लिए, देखें अनुमति पाने के लिए JSON वेब टोकन (JWT) बनाना.
प्रोवाइडर आईडी और Google Cloud प्रोजेक्ट आईडी एक ही होते हैं. Fleet Engine Deliveryies API की उपयोगकर्ता गाइड देखें हमारा वीडियो देखें.
यहां दिए गए उदाहरण में, ऐक्सेस टोकन देने वाली कंपनी के बारे में बताया गया है:
#import "SampleAccessTokenProvider.h"
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
// SampleAccessTokenProvider.h
@interface SampleAccessTokenProvider : NSObject<GMTDAuthorization>
@end
static NSString *const PROVIDER_URL = @"INSERT_YOUR_TOKEN_PROVIDER_URL";
// SampleAccessTokenProvider.m
@implementation SampleAccessTokenProvider{
// The cached vehicle token.
NSString *_cachedVehicleToken;
// Keep track of the vehicle ID the cached token is for.
NSString *_lastKnownVehicleID;
// Keep track of when tokens expire for caching.
NSTimeInterval _tokenExpiration;
}
- (void)fetchTokenWithContext:(nullable GMTDAuthorizationContext *)authorizationContext
completion:(nonnull GMTDAuthTokenFetchCompletionHandler)completion {
if (!completion) {
NSAssert(NO, @"%s encountered an unexpected nil completion.", __PRETTY_FUNCTION__);
return;
}
// Get the vehicle ID from the authorizationContext. This is set by the Driver SDK.
NSString *vehicleID = authorizationContext.vehicleID;
if (!vehicleID) {
NSAssert(NO, @"Vehicle ID is missing from authorizationContext.");
return;
}
// Clear cached vehicle token if vehicle ID has changed.
if (![_lastKnownVehicleID isEqual:vehicleID]) {
_tokenExpiration = 0.0;
_cachedVehicleToken = nil;
}
_lastKnownVehicleID = vehicleID;
// Clear cached vehicle token if it has expired.
if ([[NSDate date] timeIntervalSince1970] > _tokenExpiration) {
_cachedVehicleToken = nil;
}
// If appropriate, use the cached token.
if (_cachedVehicleToken) {
completion(_cachedVehicleToken, nil);
return;
}
// Otherwise, try to fetch a new token from your server.
NSURL *requestURL = [NSURL URLWithString:PROVIDER_URL];
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL:requestURL];
request.HTTPMethod = @"GET";
// Replace the following key values with the appropriate keys based on your
// server's expected response.
NSString *vehicleTokenKey = @"VEHICLE_TOKEN_KEY";
NSString *tokenExpirationKey = @"TOKEN_EXPIRATION";
__weak typeof(self) weakSelf = self;
void (^handler)(NSData *_Nullable data, NSURLResponse *_Nullable response,
NSError *_Nullable error) =
^(NSData *_Nullable data, NSURLResponse *_Nullable response, NSError *_Nullable error) {
typeof(self) strongSelf = weakSelf;
if (error) {
completion(nil, error);
return;
}
NSError *JSONError;
NSMutableDictionary *JSONResponse =
[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&JSONError];
if (JSONError) {
completion(nil, JSONError);
return;
} else {
// Sample code only. No validation logic.
id expirationData = JSONResponse[tokenExpirationKey];
if ([expirationData isKindOfClass:[NSNumber class]]) {
NSTimeInterval expirationTime = ((NSNumber *)expirationData).doubleValue;
strongSelf->_tokenExpiration = [[NSDate date] timeIntervalSince1970] + expirationTime;
}
strongSelf->_cachedVehicleToken = JSONResponse[vehicleTokenKey];
completion(JSONResponse[vehicleTokenKey], nil);
}
};
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *mainQueueURLSession =
[NSURLSession sessionWithConfiguration:config delegate:nil
delegateQueue:[NSOperationQueue mainQueue]];
NSURLSessionDataTask *task = [mainQueueURLSession dataTaskWithRequest:request completionHandler:handler];
[task resume];
}
@end
DeliveryDriverAPI इंस्टेंस बनाएं
GMTDDeliveryVehicleReporter
इंस्टेंस पाने के लिए, आपको पहले
providerID का इस्तेमाल करने वाले GMTDDeliveryDriverAPI
इंस्टेंस,
वाहन आईडी, ड्राइवर कॉन्टेक्स्ट, और accessTokenProvider. providerID एक ही है
Google Cloud प्रोजेक्ट आईडी. साथ ही, GMTDDeliveryVehicleReporter
को ऐक्सेस किया जा सकता है
सीधे ड्राइवर एपीआई से इंस्टेंस.
नीचे दिए गए उदाहरण में, GMTDDeliveryDriverAPI
इंस्टेंस बनाया गया है:
#import “SampleViewController.h”
#import “SampleAccessTokenProvider.h”
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
GMSMapView *_mapView;
}
- (void)viewDidLoad {
NSString *vehicleID = @"INSERT_CREATED_VEHICLE_ID";
SampleAccessTokenProvider *accessTokenProvider =
[[SampleAccessTokenProvider alloc] init];
GMTDDriverContext *driverContext =
[[GMTDDriverContext alloc] initWithAccessTokenProvider:accessTokenProvider
providerID:PROVIDER_ID
vehicleID:vehicleID
navigator:_mapView.navigator];
GMTDDeliveryDriverAPI *deliveryDriverAPI = [[GMTDDeliveryDriverAPI alloc] initWithDriverContext:driverContext];
}
वाहन के बारे में जानकारी देने वाली सुविधा के इवेंट भी सुनें
GMTDDeliveryVehicleReporter
समय-समय पर वाहन को तब अपडेट करता है, जब
locationTrackingEnabled
का जवाब हां है. इन समय-समय पर होने वाले अपडेट का जवाब देने के लिए, किसी भी समय
ऑब्जेक्ट, GMTDDeliveryVehicleReporter
इवेंट की सदस्यता ले सकता है. इसके लिए, वह
GMTDVehicleReporterListener
प्रोटोकॉल का.
आपके पास इन इवेंट को मैनेज करने का विकल्प होता है:
vehicleReporter:didSucceedVehicleUpdate
इससे ड्राइवर ऐप्लिकेशन को यह सूचना मिलती है कि बैकएंड सेवाओं को गाड़ी की जगह और स्थिति की जानकारी अपडेट करें.
vehicleReporter:didFailVehicleUpdate:withError
लिसनर को सूचना दी जाती है कि गाड़ी को अपडेट नहीं किया जा सका. जगह के तौर पर ट्रैकिंग सक्षम है,
GMTDDeliveryVehicleReporter
भेजना जारी रखता है फ़्लीट इंजन बैकएंड का नया डेटा.
नीचे दिए गए उदाहरण में, इन इवेंट को हैंडल किया गया है:
SampleViewController.h
@interface SampleViewController : UIViewController<GMTDVehicleReporterListener>
@end
SampleViewController.m
#import “SampleViewController.h”
#import “SampleAccessTokenProvider.h”
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
GMSMapView *_mapView;
}
- (void)viewDidLoad {
// ASSUMES YOU IMPLEMENTED HAVE THE SAMPLE CODE UP TO THIS STEP.
[ridesharingDriverAPI.vehicleReporter addListener:self];
}
- (void)vehicleReporter:(GMTDDeliveryVehicleReporter *)vehicleReporter didSucceedVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate {
// Handle update succeeded.
}
- (void)vehicleReporter:(GMTDDeliveryVehicleReporter *)vehicleReporter didFailVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate withError:(NSError *)error {
// Handle update failed.
}
@end
जगह की जानकारी ट्रैक करने की सुविधा चालू करें
जगह की जानकारी ट्रैक करने की सुविधा चालू करने के लिए, आपका ऐप्लिकेशन locationTrackingEnabled
को YES
पर सेट कर सकता है
GMTDDeliveryVehicleReporter
को. फिर GMTDDeliveryVehicleReporter
यह होगा =
अपने आप स्थान अपडेट भेजें. जब GMSNavigator
नेविगेशन में हो
मोड (जब डेस्टिनेशन setDestinations
के ज़रिए सेट किया गया हो) और
locationTrackingEnabled
को YES
पर सेट किया गया है, GMTDDeliveryVehicleReporter
साथ ही, रास्ते और ETA के अपडेट अपने-आप भेजे जाने की अनुमति दें.
इन अपडेट के दौरान सेट किया गया रास्ता वही होगा जो ड्राइवर के पास है
पर नेविगेट करना चाहिए. इस तरह, शिपमेंट ट्रैकिंग के काम करने के लिए
-setDestinations:callback:
से होकर गुज़रने वाला वेपॉइंट
डेस्टिनेशन को फ़्लीट इंजन बैकएंड में सेट किया गया है.
यहां दिए गए उदाहरण में, जगह की जानकारी ट्रैक करने की सुविधा चालू की गई है:
SampleViewController.m
#import “SampleViewController.h”
#import “SampleAccessTokenProvider.h”
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
GMSMapView *_mapView;
}
- (void)viewDidLoad {
// ASSUMES YOU IMPLEMENTED HAVE THE SAMPLE CODE UP TO THIS STEP.
deliveryDriverAPI.vehicleReporter.locationTrackingEnabled = YES;
}
@end
डिफ़ॉल्ट रूप से, रिपोर्टिंग अंतराल 10 सेकंड का होता है, लेकिन रिपोर्टिंग अंतराल
locationUpdateInterval
के साथ बदला जाएगा. अपडेट करने के लिए, तय इंटरवल का कम से कम इस्तेमाल
5 सेकंड का है. अपडेट के लिए ज़्यादा से ज़्यादा 60 सेकंड का इंटरवल इस्तेमाल किया जा सकता है. ज़्यादा बार
अपडेट की वजह से, अनुरोध धीमे हो सकते हैं और गड़बड़ियां हो सकती हैं.
जगह की जानकारी के अपडेट बंद करें
आपका ऐप्लिकेशन, वाहन की जगह की जानकारी अपडेट करने की सुविधा बंद कर सकता है. उदाहरण के लिए, जब किसी
ड्राइवर की शिफ़्ट खत्म हो रही है, आपका ऐप्लिकेशन locationTrackingEnabled
को NO
पर सेट कर सकता है.
_vehicleReporter.locationTrackingEnabled = NO
अपडेट_मास्क से जुड़ी गड़बड़ियां ठीक करना
जब GMTDDeliveryVehicleReporter
वाहन का अपडेट भेजता है, तो update_mask
मास्क खाली होने पर गड़बड़ी हो सकती है. साथ ही, यह आम तौर पर पहली बार
स्टार्टअप के बाद अपडेट करें. नीचे दिए गए उदाहरण में, इस गड़बड़ी को ठीक करने का तरीका बताया गया है:
Swift
import GoogleRidesharingDriver
class VehicleReporterListener: NSObject, GMTDVehicleReporterListener {
func vehicleReporter(
_ vehicleReporter: GMTDVehicleReporter,
didFail vehicleUpdate: GMTDVehicleUpdate,
withError error: Error
) {
let fullError = error as NSError
if let innerError = fullError.userInfo[NSUnderlyingErrorKey] as? NSError {
let innerFullError = innerError as NSError
if innerFullError.localizedDescription.contains("update_mask cannot be empty") {
emptyMaskUpdates += 1
return
}
}
failedUpdates += 1
}
override init() {
emptyMaskUpdates = 0
failedUpdates = 0
}
}
Objective-C
#import "VehicleReporterListener.h"
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
@implementation VehicleReporterListener {
NSInteger emptyMaskUpdates = 0;
NSInteger failedUpdates = 0;
}
- (void)vehicleReporter:(GMTDVehicleReporter *)vehicleReporter
didFailVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate
withError:(NSError *)error {
for (NSError *underlyingError in error.underlyingErrors) {
if ([underlyingError.localizedDescription containsString:@"update_mask cannot be empty"]) {
emptyMaskUpdates += 1;
return;
}
}
failedUpdates += 1
}
@end