मुख्य कंटेंट तक स्किप करें

iPhone मिलने की सूचना दें

डिवाइस से आए find-iPhone अनुरोध का जवाब दें, ऐप में iPhone-side alert संभालें और उपयोगकर्ता के iPhone ढूँढ लेने पर अनुरोध करने वाले डिवाइस को सूचित करें।

यह डिवाइस ढूँढें workflow की उलटी दिशा है: इसे जुड़ा डिवाइस शुरू करता है, जबकि iPhone ढूँढने के लिए ध्वनि, vibration और UI होस्ट ऐप संभालता है।

पहले की आवश्यकताएँ​

iPhone मिलने की सूचना देने से पहले सुनिश्चित करें:

  • अनुरोध करने वाला डिवाइस connected और ready रहता है।
  • ऐप deviceDidRequestStartFindingPhone और deviceDidRequestStopFindingPhone, या उनके SDKDelegate callbacks को observe करता है।
  • डिवाइस FindPhoneStateReportingAPI का समर्थन करता है।
  • उपयोगकर्ता के iPhone मिल जाने की पुष्टि करने के बाद ऐप ने iPhone-side indication बंद कर दिया है।

API संदर्भ​

फ्रेमवर्क​

AIBuds.xcframework

Import​

Swift
import AIBuds

प्रोटोकॉल​

notifyPhoneFound method, FindPhoneStateReportingAPI में परिभाषित है।

Swift
/// Reports to a connected device that its find-phone request has been resolved.
///
/// Find-phone is initiated by the device rather than by this API. Observe
/// `DeviceDelegate.deviceDidRequestStartFindingPhone(_:)` and
/// `DeviceDelegate.deviceDidRequestStopFindingPhone(_:)`, or the corresponding
/// `SDKDelegate` callbacks, to start and stop the app's phone-side alert.
///
/// After the user locates the phone, call `notifyPhoneFound(_:)` to notify the
/// requesting device. To make the connected device itself emit a locate
/// indication, use `DeviceFindAPI` instead.
public protocol FindPhoneStateReportingAPI: DeviceAPI {
    /// Notifies the connected device that the user has found the phone.
    ///
    /// Call this after handling a device-originated find-phone request and
    /// stopping the phone-side alert. The completion reports delivery and
    /// command processing; it does not represent a new find-phone request.
    /// - Parameters:
    ///   - completion: Called when command processing completes.
    ///     - success: `true` when the device accepted the report; otherwise,
    ///       `false`.
    ///     - error: The command or communication error, or `nil` on success.
    func notifyPhoneFound(_ completion: AIBudsCompletionHandler?)
}

Instance method​

जुड़े डिवाइस को बताता है कि उपयोगकर्ता ने iPhone ढूँढ लिया है।

Swift
/// Notifies the connected device that the user has found the phone.
///
/// Call this after handling a device-originated find-phone request and
/// stopping the phone-side alert. The completion reports delivery and
/// command processing; it does not represent a new find-phone request.
/// - Parameters:
///   - completion: Called when command processing completes.
///     - success: `true` when the device accepted the report; otherwise,
///       `false`.
///     - error: The command or communication error, or `nil` on success.
func notifyPhoneFound(_ completion: AIBudsCompletionHandler?)

API संदर्भ में notifyPhoneFound देखें।

पैरामीटर​

पैरामीटरप्रकारविवरण
completionAIBudsCompletionHandler?Report delivery और command processing पूरा होने पर call होने वाला optional handler।

Callback पैरामीटर:

नामप्रकारविवरण
successBool / BOOLडिवाइस ने iPhone-found report स्वीकार किया हो तो true, अन्यथा false।
errorNSError?Command या communication error; सफल होने पर nil।

Return value​

यह method सीधे कोई value return नहीं करता। इसका completion अनुरोध करने वाले डिवाइस तक परिणाम पहुँचने की सूचना देता है; नया find-iPhone अनुरोध शुरू नहीं करता।

उपयोग के उदाहरण​

डिवाइस से आने वाले start और stop requests observe करें। उपयोगकर्ता के iPhone मिल जाने की पुष्टि करने पर परिणाम बताने से पहले iPhone-side alert बंद करें।

Swift
import AIBuds

final class FindPhoneCoordinator: NSObject, DeviceDelegate {
    private weak var requestingDevice: DeviceConvertible?

    func deviceDidRequestStartFindingPhone(_ device: DeviceConvertible) {
        requestingDevice = device
        DispatchQueue.main.async {
            self.startPhoneAlert()
        }
    }

    func deviceDidRequestStopFindingPhone(_ device: DeviceConvertible) {
        DispatchQueue.main.async {
            self.stopPhoneAlert()
        }
    }

    func userConfirmedPhoneFound() {
        stopPhoneAlert()

        guard let reporter = requestingDevice as? FindPhoneStateReportingAPI else {
            print("Device cannot receive a phone-found report")
            return
        }

        reporter.notifyPhoneFound { success, error in
            guard success else {
                print(
                    "Failed to report phone found: \(error?.localizedDescription ?? "Unknown error")"
                )
                return
            }
            print("Phone-found report accepted")
        }
    }
}

Error handling​

iPhone-side alert state को report delivery से अलग रखें। डिवाइस के कहने या उपयोगकर्ता के iPhone मिल जाने की पुष्टि करने पर alert तुरंत बंद करें; फिर notifyPhoneFound communication error दिखाएँ, लेकिन alert अपने-आप दोबारा शुरू न करें।

बेहतर तरीके​

  1. डिवाइस अनुरोध पर प्रतिक्रिया दें: संबंधित delegate callback मिलने के बाद ही iPhone-side indication शुरू करें।
  2. iPhone अनुभव ऐप में संभालें: ध्वनि, vibration, permissions, background behavior और UI होस्ट ऐप में लागू करें।
  3. सूचना देने से पहले रोकें: notifyPhoneFound(_:) call करने से पहले local alert resources बंद करें।
  4. अनुरोध करने वाला डिवाइस बनाए रखें: Report उसी जुड़े डिवाइस को भेजें जिसने अनुरोध शुरू किया था।
  5. UI को main queue पर अपडेट करें: Delegate और completion callbacks से UIKit work main queue पर भेजें।

ध्यान देने योग्य बातें​

  • notifyPhoneFound(_:) परिणाम की पुष्टि करता है; find-iPhone operation शुरू नहीं करता।
  • डिवाइस से आया stop request ऐप को iPhone-side indication बंद करने को कहता है। यह उपयोगकर्ता द्वारा पुष्टि किए गए iPhone-found report से अलग है।
  • जब ऐप को जुड़े डिवाइस पर locate indication दिखाना हो तब DeviceFindAPI उपयोग करें।