डिवाइस अनपेयर करें
डिवाइस अनपेयर ऑपरेशन डिवाइस और कनेक्टेड डिवाइस के बीच पेयरिंग रिलेशनशिप को हटा देता है। यह ऑपरेशन तब उपयोगी होता है जब आपको डिवाइस को स्थायी रूप से डिस्कनेक्ट करने की आवश्यकता होती है या किसी अन्य डिवाइस के साथ पेयरिंग की तैयारी करनी होती है।
पूर्वापेक्षाएं
अनपेयर करने से पहले, सुनिश्चित करें:
- डिवाइस कनेक्ट है और स्थिर स्थिति में है
- कोई भी आवश्यक डेटा सिंक्रनाइज़ेशन पूर्ण हो गया है
- उपयोगकर्ता समझता है कि अनपेयरिंग के बाद डिवाइस डिस्कनेक्ट हो जाएगा
AI की सहायता से लागू करें
इस वर्कफ़्लो को AI से लागू करें
आधिकारिक “AIBuds डिवाइस अनपेयरिंग लागू करें” स्किल से वर्कफ़्लो को अपने ऐप के अनुसार लागू करें।
https://docs-aibuds.github.io/hi/skills/implement-aibuds-unpair-device को पढ़ें और निर्देशों का पालन करें। इस स्किल से “AIBuds डिवाइस अनपेयरिंग लागू करें” को इस iOS प्रोजेक्ट में लागू करें और परिणाम सत्यापित करें।API संदर्भ
फ्रेमवर्क
AIBuds.xcframework
आयात
जिन फ़ाइलों में आप SDK का उपयोग करना चाहते हैं, उसमें मुख्य हेडर आयात करें:
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>प्रोटोकॉल
unpair मेथड निम्नलिखित प्रोटोकॉल में परिभाषित है। प्रोटोकॉल बेस डिवाइस API प्रोटोकॉल से इनहेरिट करता है।
- Swift
- Objective-C
/// Defines common device operations including unpairing
protocol DeviceCommonAPI: DeviceAPI {
/// Unpairs the device
/// - Parameters:
/// - completion: A completion callback that returns the operation result
/// - success: `true` if the operation succeeds, `false` otherwise
/// - error: An `NSError` object describing the error that occurred, or `nil` if the operation succeeds
func unpair(_ completion: AIBudsCompletionHandler?)
}/// Defines common device operations including unpairing
@protocol AIBudsDeviceCommonAPI <AIBudsDeviceAPI>
/// Unpairs the device
/// - Parameters:
/// - completion: A completion callback that returns the operation result
/// - success: `true` if the operation succeeds, `false` otherwise
/// - error: An `NSError` object describing the error that occurred, or `nil` if the operation
/// succeeds
- (void)unpairWithCompletion:(AIBudsCompletionHandler)completion;
@endइंस्टेंस मेथड
कनेक्टेड डिवाइस से डिवाइस का पेयरिंग हटाता है।
iOS 13.0+
- Swift
- Objective-C
/// Unpairs the device
/// - Parameters:
/// - completion: A completion callback that returns the operation result
/// - success: `true` if the operation succeeds, `false` otherwise
/// - error: An `NSError` object describing the error that occurred, or `nil` if the operation succeeds
func unpair(_ completion: AIBudsCompletionHandler?)/// Unpairs the device
/// - Parameters:
/// - completion: A completion callback that returns the operation result
/// - success: `true` if the operation succeeds, `false` otherwise
/// - error: An `NSError` object describing the error that occurred, or `nil` if the operation
/// succeeds
- (void)unpairWithCompletion:(AIBudsCompletionHandler)completion;पैरामीटर
| पैरामीटर | प्रकार | विवरण |
|---|---|---|
| completion | AIBudsCompletionHandler? | वैकल्पिक कम्प्लीशन कॉलबैक जो ऑपरेशन पूरा होने पर कॉल किया जाता है। |
कॉलबैक पैरामीटर:
| नाम | प्रकार | विवरण |
|---|---|---|
| success | Bool | ऑपरेशन सफल होने पर true, अन्यथा false |
| error | NSError? | त्रुटि होने पर त्रुटि जानकारी होती है, अन्यथा nil |
रिटर्न वैल्यू
यह मेथड सीधे कोई वैल्यू रिटर्न नहीं करता। रिज़ल्ट कम्प्लीशन कॉलबैक के माध्यम से प्रदान किया जाता है।
उपयोग उदाहरण
- Swift
- Objective-C
import AIBuds
class DeviceManager {
/// Connected device
weak var device: DeviceConvertible?
/// Unpairs the connected device
func unpairDevice() {
// Check if the device supports the unpair protocol
guard let device = device as? DeviceCommonAPI else {
print("Device does not support unpairing")
return
}
// Execute unpair with completion handler
device.unpair { [weak self] success, error in
// Handle failure case
if !success {
let errorMessage = {
if let error = error {
return "\(error)"
}
return "Unknown error"
}()
print("Unpair failed: \(errorMessage)")
return
}
// Handle success case
print("Unpair completed successfully")
}
}
}#import <AIBuds/AIBuds.h>
@interface DeviceManager ()
/// Connected device
@property(weak, nonatomic) id<AIBudsDeviceConvertible> device;
@end
@implementation DeviceManager
- (void)unpairDevice {
__weak typeof(self) weakSelf = self;
id<AIBudsDeviceCommonAPI> device = (id<AIBudsDeviceCommonAPI>)self.device;
// Check if the device supports the unpair protocol
if ([device conformsToProtocol:@protocol(AIBudsDeviceCommonAPI)]) {
// Execute unpair with completion handler
[device unpairWithCompletion:^(BOOL success, NSError *_Nullable error) {
// Handle failure case
if (!success) {
NSLog(@"Unpair failed: %@", error);
return;
}
// Handle success case
NSLog(@"Unpair completed successfully");
}];
}
}
@endत्रुटि हैंडलिंग
कम्प्लीशन हैंडलर निम्नलिखित त्रुटि प्रकार लौटा सकता है:
त्रुटि डोमेन: AIBudsSDK.ErrorDomain
- Swift
- Objective-C
| त्रुटि कोड | विवरण | रिकवरी सुझाव |
|---|---|---|
| .deviceNotConnected | डिवाइस कनेक्ट नहीं है | सुनिश्चित करें कि डिवाइस पेयर्ड और कनेक्टेड है |
| .bleCommandExecFailedDueToTimeout | ऑपरेशन टाइम आउट हो गया | ऑपरेशन पुनः प्रयास करें |
| .deviceBusy | डिवाइस दूसरे ऑपरेशन में व्यस्त है | चल रहे ऑपरेशन पूर्ण होने तक प्रतीक्षा करें |
| .deviceNotSupport | इस डिवाइस पर अनपेयर सपोर्टेड नहीं है | कॉल करने से पहले डिवाइस क्षमताओं की जांच करें |
| त्रुटि कोड | विवरण | रिकवरी सुझाव |
|---|---|---|
| AIBudsSdkErrorCodeDeviceNotConnected | डिवाइस कनेक्ट नहीं है | सुनिश्चित करें कि डिवाइस पेयर्ड और कनेक्टेड है |
| AIBudsSdkErrorCodeBleCommandExecFailedDueToTimeout | ऑपरेशन टाइम आउट हो गया | ऑपरेशन पुनः प्रयास करें |
| AIBudsSdkErrorCodeDeviceBusy | डिवाइस दूसरे ऑपरेशन में व्यस्त है | चल रहे ऑपरेशन पूर्ण होने तक प्रतीक्षा करें |
| AIBudsSdkErrorCodeDeviceNotSupport | इस डिवाइस पर अनपेयर सपोर्टेड नहीं है | कॉल करने से पहले डिवाइस क्षमताओं की जांच करें |
सर्वोत्तम अभ्यास
-
उपयोगकर्ता से पुष्टि करें: अनपेयर शुरू करने से पहले हमेशा एक पुष्टि संवाद प्रदर्शित करें, क्योंकि यह ऑपरेशन डिवाइस को डिस्कनेक्ट कर देगा और पुनः पेयरिंग की आवश्यकता होगी।
-
बैकग्राउंड एक्जीक्यूशन को हैंडल करें: UI अपडेट करते समय कम्प्लीशन हैंडलर को
DispatchQueue.main.asyncब्लॉक में रैप करें। -
वीक सेल्फ रेफरेंस: रिटेन साइकिल से बचने के लिए कम्प्लीशन हैंडलर में
[weak self]का उपयोग करें। -
प्रोटोकॉल कंफर्मेंस की जांच करें: मेथड को कॉल करने से पहले सत्यापित करें कि डिवाइस
DeviceCommonAPIप्रोटोकॉल का अनुपालन करता है। -
डिस्कनेक्शन को हैंडल करें: सफल अनपेयर के बाद, डिवाइस डिस्कनेक्शन को सुव्यवस्थित रूप से हैंडल करें और पुनः पेयरिंग के लिए मार्गदर्शन प्रदान करें।
प्लेटफॉर्म सीमाएं
iOS सिस्टम ब्लूटूथ सीमा
iOS पर, सिस्टम ब्लूटूथ सेटिंग्स एप्लिकेशन को प्रोग्रामेटिक रूप से ब्लूटूथ डिवाइस का पेयरिंग हटाने की अनुमति नहीं देती हैं। यह Apple द्वारा सुरक्षा और उपयोगकर्ता नियंत्रण के लिए लगाई गई सिस्टम-स्तरीय प्रतिबंध है।
इसका मतलब:
unpairकॉल करने के बाद भी, iOS डिवाइस के लिए BLE बॉन्डिंग जानकारी बनाए रखेगा- ऐप रीस्टार्ट या ब्लूटूथ सक्षम होने पर डिवाइस स्वचालित रूप से पुनः कनेक्ट हो सकता है
- डिवाइस iOS सेटिंग्स > ब्लूटूथ में दिखाई देता रहेगा
अनुशंसित उपयोगकर्ता मार्गदर्शन:
अपने iOS ऐप में अनपेयर कार्यक्षमता लागू करते समय, आपको उपयोगकर्ताओं को iOS सेटिंग्स से मैन्युअल रूप से अनपेयर करने के लिए मार्गदर्शन करना चाहिए:
- पूर्ण अनपेयर के लिए: उपयोगकर्ताओं को सेटिंग्स > ब्लूटूथ पर जाने, डिवाइस खोजने, "i" आइकन टैप करने और "इस डिवाइस को भूलें" चुनने के लिए कहें
- स्पष्ट UI फीडबैक प्रदान करें: जब उपयोगकर्ता अनपेयर का अनुरोध करे तो निर्देश या ब्लूटूथ सेटिंग्स के लिए डीप लिंक दिखाएं
- ऐप-स्तरीय डिस्कनेक्शन:
unpairमेथड अभी भी आपके ऐप के दृष्टिकोण से डिवाइस को डिस्कनेक्ट करेगा, लेकिन सिस्टम बॉन्डिंग बनी रहेगी
- Swift
- Objective-C
/// Prompt user to unpair from iOS Settings
func promptUserToUnpairFromSettings() {
// Show alert with instructions
let alert = UIAlertController(
title: "Unpair Device",
message:
"To completely unpair the device, go to Settings > Bluetooth, find your device, tap the 'i' icon next to it, then select 'Forget This Device'.",
preferredStyle: .alert
)
alert.addAction(
UIAlertAction(title: "Open Settings", style: .default) { _ in
// Deep link to Bluetooth settings
if let url = URL(string: "App-prefs:Bluetooth") {
UIApplication.shared.open(url)
}
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
// Present alert
if let viewController = UIApplication.shared.windows.first?.rootViewController {
viewController.present(alert, animated: true)
}
}/// Prompt user to unpair from iOS Settings
- (void)promptUserToUnpairFromSettings {
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"Unpair Device"
message:@"To completely unpair the device, go to Settings > Bluetooth, "
@"find your device, tap the 'i' icon next to it, then select "
@"'Forget This Device'."
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Open Settings"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
NSURL *url =
[NSURL URLWithString:@"App-prefs:Bluetooth"];
if (url && [[UIApplication sharedApplication]
canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url
options:@{}
completionHandler:nil];
}
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil]];
UIViewController *viewController =
[UIApplication sharedApplication].windows.firstObject.rootViewController;
[viewController presentViewController:alert animated:YES completion:nil];
}नोट्स
- अनपेयर कमांड एक्जीक्यूट होने के बाद डिवाइस डिस्कनेक्ट हो जाएगा
- डिवाइस को फिर से कनेक्ट करने के लिए पुनः पेयरिंग की आवश्यकता होगी
- सभी पेयरिंग जानकारी दोनों डिवाइस से हटा दी जाएगी
- कोई भी चल रहे ऑपरेशन बाधित हो जाएंगे
- अनपेयर होने में कुछ सेकंड लग सकते हैं