Aygıt Saatini Eşitleme
Bağlı aygıtın dahili saatini geçerli saatle eşitleyin. Belirli bir tarih vermeden aygıt saatini hizalamak istediğinizde bu işlemi kullanın.
Ön Koşullar
Aygıt saatini eşitlemeden önce şunları doğrulayın:
- Aygıt bağlı ve kararlı durumdadır
- Aygıt
DeviceInfoAPIprotokolünü destekler
API Reference
Framework
AIBuds.xcframework
Import
SDK'yı kullanacağınız dosyalarda ana framework'ü içe aktarın:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>Protokol
syncDeviceTime yöntemi DeviceInfoAPI içinde tanımlıdır. Bu protokol temel aygıt API protokolünden türetilir.
- Swift
- Objective-C
/// The protocol for device information related API.
protocol DeviceInfoAPI: DeviceAPI {
/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func syncDeviceTime(_ completion: AIBudsStatusCodeCompletionHandler?)
}/// The protocol for device information related API.
@protocol AIBudsDeviceInfoAPI <AIBudsDeviceAPI>
/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)syncDeviceTimeWithCompletion:(AIBudsStatusCodeCompletionHandler _Nullable)completion;
@endÖrnek Yöntemi
Aygıt saatini geçerli saatle eşitler.
- Swift
- Objective-C
/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
func syncDeviceTime(_ completion: AIBudsStatusCodeCompletionHandler?)/// Synchronizes the device time with the current time.
/// - Parameters:
/// - completion: A closure that is called when the operation completes.
/// - success: `true` if the operation was successful; otherwise `false`.
/// - statusCode: The status code returned by the device. `nil` if the operation failed.
/// - error: An `NSError` object that describes the error that occurred, or `nil` if the
/// operation was successful.
- (void)syncDeviceTimeWithCompletion:(AIBudsStatusCodeCompletionHandler _Nullable)completion;Parametreler
| Parametre | Tür | Açıklama |
|---|---|---|
completion | AIBudsStatusCodeCompletionHandler? | İşlem tamamlandığında çağrılan isteğe bağlı tamamlanma işleyicisi. |
Geri Çağrı Parametreleri:
| Ad | Tür | Açıklama |
|---|---|---|
success | Bool / BOOL | İşlem başarılıysa true; aksi halde false. |
statusCode | NSNumber? | Aygıtın döndürdüğü durum kodu. SDK, işlem başarısız olduğunda bu değerin nil olduğunu belirtir. |
error | NSError? | İşlem başarısızsa hata ayrıntıları; aksi halde nil. |
Dönüş Değeri
Bu yöntem doğrudan bir değer döndürmez. Sonuç tamamlanma işleyicisi aracılığıyla iletilir.
Kullanım Örnekleri
- Swift
- Objective-C
import AIBuds
final class DeviceManager {
/// The connected device
weak var device: DeviceConvertible?
/// Synchronizes the connected device with the current time
func synchronizeDeviceTime() {
guard let device = device as? DeviceInfoAPI else {
print("Device does not support time synchronization")
return
}
device.syncDeviceTime { success, statusCode, error in
if !success {
print(
"Time synchronization failed: "
+ (error?.localizedDescription ?? "Unknown error")
)
return
}
print(
"Time synchronized successfully. Status code: " + (statusCode?.stringValue ?? "N/A")
)
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
@interface DeviceManager ()
/// The connected device
@property(weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)synchronizeDeviceTime {
id<AIBudsDeviceInfoAPI> device = (id<AIBudsDeviceInfoAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceInfoAPI)]) {
NSLog(@"Device does not support time synchronization");
return;
}
[device syncDeviceTimeWithCompletion:^(
BOOL success, NSNumber *_Nullable statusCode, NSError *_Nullable error) {
if (!success) {
NSLog(@"Time synchronization failed: %@",
error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"Time synchronized successfully. Status code: %@", statusCode ?: @"N/A");
}];
}
@endHata Yönetimi
Tamamlanma işleyicisi eşitleme işleminin sonucunu bildirir:
- İşlemi tamamlanmış kabul etmeden önce
successdeğerini kontrol edin. successdeğerifalseise hata ayrıntıları içinerrordeğerini kullanın.- Varsa tanılama veya aygıta özgü işleme için
statusCodedeğerini koruyun. - Hedef aygıt için belgelenmedikçe belirli bir hata veya durum kodu varsaymayın.
En İyi Uygulamalar
-
Protokol Uyumluluğunu Denetleyin: Yöntemi çağırmadan önce aygıtın
DeviceInfoAPIdesteğini doğrulayın. -
Bağlantıdan Sonra Çağırın: Yalnızca aygıt bağlanıp hazır olduktan sonra eşitleyin.
-
Tüm Completion Değerlerini İşleyin:
success,statusCodeveerrordeğerlerini birlikte değerlendirin; yalnızcaerrordeğerine güvenmeyin. -
Arayüzü Ana Kuyrukta Güncelleyin: Tamamlanma geri çağrısına bağlı UIKit güncellemelerini ana kuyruğa aktarın.
Notlar
syncDeviceTimehedef birDatekabul etmez; belirli bir tarih vermeniz gerekiyorsasetDeviceTime(to:completion:)kullanın.- Genel API geçerli saatle eşitlemeyi tanımlar ancak UTC dönüşüm sözleşmesi belirtmez.
- Saat eşitleme desteği aygıt modeline ve firmware sürümüne göre değişebilir.