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:
- requesting device remains connected 및 ready.
- 앱 observes
deviceDidRequestStartFindingPhone및deviceDidRequestStopFindingPhone, 또는 correspondingSDKDelegate콜백. - 기기 supports
FindPhoneStateReportingAPI. - 앱 has stopped its iPhone-side indication 후에 user confirms iPhone was found.
API Reference
Framework
AIBuds.xcframework
Import
- Swift
- Objective-C
import AIBuds#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>프로토콜
notifyPhoneFound method 입니다 defined 에서 FindPhoneStateReportingAPI.
- Swift
- Objective-C
/// 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?)
}/// Reports to a connected device that its find-phone request has been resolved.
///
/// Find-phone is initiated by the device. Observe the device or SDK delegate
/// callbacks to start and stop the app's phone-side alert.
@protocol AIBudsFindPhoneStateReportingAPI <AIBudsDeviceAPI>
/// Notifies the connected device that the user has found the phone.
///
/// Call this after stopping the phone-side alert. The completion reports
/// delivery and command processing; it does not start a new 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.
- (void)notifyPhoneFoundWithCompletion:(AIBudsCompletionHandler _Nullable)completion;
@end인스턴스 메서드
Notifies connected device user has found iPhone.
- Swift
- Objective-C
/// 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 the connected device that the user has found the phone.
///
/// Call this after stopping the phone-side alert. The completion reports
/// delivery and command processing; it does not start a new 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.
- (void)notifyPhoneFoundWithCompletion:(AIBudsCompletionHandler _Nullable)completion;See notifyPhoneFound 에서 API Reference.
매개변수
| 매개변수 | 타입 | 설명 |
|---|---|---|
completion | AIBudsCompletionHandler? | 선택적 handler called 때 보고서 delivery 및 command processing complete. |
콜백 Parameters:
| 이름 | 타입 | 설명 |
|---|---|---|
success | Bool / BOOL | true 때 기기 accepted iPhone-found 보고서; 그렇지 않으면 false. |
error | NSError? | 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
- Objective-C
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")
}
}
}#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
@property(nonatomic, weak) id<AIBudsDeviceConvertible> requestingDevice;
- (void)deviceDidRequestStartFindingPhone:(id<AIBudsDeviceConvertible>)device {
self.requestingDevice = device;
dispatch_async(dispatch_get_main_queue(), ^{
[self startPhoneAlert];
});
}
- (void)deviceDidRequestStopFindingPhone:(id<AIBudsDeviceConvertible>)device {
dispatch_async(dispatch_get_main_queue(), ^{
[self stopPhoneAlert];
});
}
- (void)userConfirmedPhoneFound {
[self stopPhoneAlert];
id<AIBudsFindPhoneStateReportingAPI> reporter =
(id<AIBudsFindPhoneStateReportingAPI>)self.requestingDevice;
if (![reporter conformsToProtocol:@protocol(AIBudsFindPhoneStateReportingAPI)]) {
NSLog(@"Device cannot receive a phone-found report");
return;
}
[reporter notifyPhoneFoundWithCompletion:^(BOOL success, NSError *_Nullable error) {
if (!success) {
NSLog(@"Failed to report phone found: %@",
error.localizedDescription ?: @"Unknown error");
return;
}
NSLog(@"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.
권장 사항
- React Device Requests: 시작 iPhone-side indication 만 후에 corresponding delegate 콜백.
- Own iPhone Experience: Implement sound, vibration, permissions, 백그라운드 behavior, 및 UI 에서 호스트 앱.
- 중지 전에 Reporting: 중지 로컬 alert resources 전에 calling
notifyPhoneFound(_:). - Retain Requesting Device: 전송 보고서 same connected device initiated request.
- 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.