- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 Apple Watch 应用程序,我需要在父应用程序发生某些更改时通知 watch 。我正在使用 GitHub 上的 MMWormhole 库,但我无法将消息从手机传递到 watch 。这是我的代码,您知道为什么会这样吗?
我的主要 viewController 代码如下所示
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:@"com.mycompany.myapp"
optionalDirectory:@"wormhole"];
NSString *myString = [[NSString alloc] initWithFormat:@"Test String"];
[self.wormhole passMessageObject:@{@"string" : myString}
identifier:@"messageIdentifier"];
我的 WatchkitExtension
中的 InterfaceController
看起来像这样:
InterfaceController.m
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Initialize the wormhole
self.wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:@"com.mycompany.myapp"
optionalDirectory:@"wormhole"];
// Obtain an initial value for the selection message from the wormhole
id messageObject = [self.wormhole messageWithIdentifier:@"messageIdentifier"];
NSString *string = [messageObject valueForKey:@"string"];
if (string != nil) {
NSLog(string);
[myLabel setText:string];
}
// Listen for changes to the selection message. The selection message contains a string value
// identified by the selectionString key. Note that the type of the key is included in the
// name of the key.
[self.wormhole listenForMessageWithIdentifier:@"messageIdentifier" listener:^(id messageObject) {
NSString *string = [messageObject valueForKey:@"string"];
if (string != nil) {
[self.myLabel setText:string];
}
}];
}
谢谢!
最佳答案
"com.mycompany.myapp"
是您在应用中使用的真实值吗?因为组标识符必须以 group.
开头。
如果您使用错误的组标识符,则一切都会失败,因为 MMWormhole 内的 containerURLForSecurityApplicationGroupIdentifier
调用返回 nil。不幸的是,MMWormhole 的开发者没有做任何检查或断言来确保共享组标识符是正确的。
所以我建议暂时停止关注 MMWormhole。相反,请在代码的早期添加此代码(例如 applicationDidFinishLaunching
),以验证您的容器标识符是否正确:
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *appGroupContainer = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.com.mycompany.myapp"];
if (!appGroupContainer) {
NSLog(@"group identifier incorrect, or app groups not setup correctly");
}
如果您的应用组设置不正确,这会告诉您。
我不确定您设置应用组的进度,但您必须使用在项目的“应用组功能”部分中使用的组标识符。
关于ios - 使用 MMWormhole 将消息传递给 Apple Watch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29609114/
此处列出的 MMWormhole (https://github.com/mutualmobile/MMWormhole) 用于在 iPhone watch 套件扩展和 iPhone 应用程序之间共享
我正在尝试将 MMWormhole 合并到我的应用程序中 ( https://github.com/mutualmobile/MMWormhole )。 我已将其添加到 pod 文件并安装它,该文件已
我正在开发一个 Apple Watch 应用程序,我需要在父应用程序发生某些更改时通知 watch 。我正在使用 GitHub 上的 MMWormhole 库,但我无法将消息从手机传递到 watch
我希望将 MMWormhole 模块导入我的苹果 WatchKit 应用程序(快速)。由于我正在快速构建应用程序,因此我需要一个桥接 header ,因为 MMWormhole 模块是在 Object
我有一个 iPhone 应用程序并添加了一个 WatchKitExtension。我想从 iPhone 应用程序将一个 String 传递给 WatchApp,它应该更改 Watch 上的图像。 我已
我的 Apple Watch 项目是用 Swift 编写的。我已经使用 CocoaPods 安装了 MMWormhole,我按照这些链接中的描述创建了桥接头: http://bencoding.com
我正在尝试使用 MMWormhole 库将我的应用程序与 Apple Watch 进行通信。我已经通过 CocoaPods 导入了 MMWormhole 库,但是在尝试将 MMWormhole.h 文
尝试构建应用程序时,出现“链接器命令失败,退出代码为 1”错误。这是 Xcode 中的错误: Undefined symbols for architecture x86_64: "_OBJC_CLA
我是一名优秀的程序员,十分优秀!