通过 iPhone 从 Apple Watch 播放声音

Playing sound from Apple Watch through iPhone

我正在尝试将声音效果合并到我一直在开发的 Apple Watch 应用程序中(写在 Objective-C),但令我失望的是不允许第三方应用程序播放直接从手表发出声音。作为解决方法,我想看看是否有办法通过配对设备的扬声器播放指定的声音。我在这里找到了一个这样的线程:

然而,已验证答案中的 link 此时似乎已关闭。简而言之,如何通过iPhone配对的扬声器播放Apple Watch触发的音效?另外,是否可以使设备从手表振动?任何帮助是极大的赞赏。

遗憾的是,AppleWatch 不允许开发人员播放或录制音频。您可以像模拟器一样从 iPhone 扬声器播放声音。如果您在 WatchKit 扩展上实现 AVAudioPlayer,您将在 Mac 中收听,因为 iPhone 模拟器正在为您播放。

摘自 Apple 开发者论坛:

Since the code simplegames showed is running on the iPhone simulator, not the watch simulator, and the button press on the watch simulator is causing the iPhone simulator code to activate the audio player, your mac is simulating sound from the iPhone.

No. It is not possible to play sounds with WatchKit on the Apple Watch.

我得到了手表来播放这样的音频。但是它确实提供了媒体播放器。它不理想,但它有效。

#import <Foundation/Foundation.h>

NSURL *yourURL = [myBundle URLForResource:@"yourAudioFile" withExtension:@"wav"];

NSDictionary *options = @{WKMediaPlayerControllerOptionsAutoplayKey : @YES};

[self presentMediaPlayerControllerWithURL:yourURL options:options completion:^(BOOL didPlayToEnd, NSTimeInterval endTime, NSError * __nullable error) {if (error)NSLog(@"Error: %@", [error description]);}];