본문으로 건너뛰기

iPhone을 찾았다고 알리기

Respond device-originated find-iPhone request, manage iPhone-side alert 에서 앱, 및 notify requesting device 후에 user locates iPhone.

이 입니다 opposite direction 에서 Find Device: connected device initiates 이 flow, 동안 호스트 앱 owns sound, vibration, 또는 UI used locate iPhone.

사전 요구 사항

전에 reporting iPhone was found, ensure:

API Reference

Framework

AIBuds.xcframework

Import

Swift
import AIBuds

프로토콜

notifyPhoneFound method 입니다 defined 에서 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?)
}

인스턴스 메서드

Notifies connected device user has found 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?)

See notifyPhoneFound 에서 API Reference.

매개변수

매개변수타입설명
completionAIBudsCompletionHandler?선택적 handler called 때 보고서 delivery 및 command processing complete.

콜백 Parameters:

이름타입설명
successBool / BOOLtrue 때 기기 accepted iPhone-found 보고서; 그렇지 않으면 false.
errorNSError?command 또는 communication 오류, 또는 nil on 성공.

반환값

이 method 하지 않습니다 반환 value directly. Its completion 보고서 delivery 의 resolution requesting device; it 하지 않습니다 initiate new find-iPhone request.

사용 예제

Observe 기기-originated 시작 및 중지 requests. 때 user confirms iPhone has been located, 중지 iPhone-side alert 전에 reporting resolution.

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")
        }
    }
}

오류 처리

Keep iPhone-side alert state independent 에서 보고서 delivery. 중지 alert immediately 때 기기 requests it 또는 user confirms iPhone was found, then surface any notifyPhoneFound communication 오류 없이 restarting alert automatically.

권장 사항

  1. React Device Requests: 시작 iPhone-side indication 만 후에 corresponding delegate 콜백.
  2. Own iPhone Experience: Implement sound, vibration, permissions, 백그라운드 behavior, 및 UI 에서 호스트 앱.
  3. 중지 전에 Reporting: 중지 로컬 alert resources 전에 calling notifyPhoneFound(_:).
  4. Retain Requesting Device: 전송 보고서 same connected device initiated request.
  5. Update UI on 메인 큐: Dispatch UIKit work 에서 delegate 및 completion 콜백 메인 큐.

참고

  • notifyPhoneFound(_:) acknowledges resolution; it 하지 않습니다 시작 find-iPhone operation.
  • device-originated 중지 request means 앱 권장됩니다 중지 its iPhone-side indication. It 입니다 separate 에서 user-confirmed iPhone-found 보고서.
  • 사용 DeviceFindAPI 때 앱 needs connected device itself present locate indication.