NSUserActivity切换不适用于自定义数据 [英] NSUserActivity handoff not working for custom data

查看:244
本文介绍了NSUserActivity切换不适用于自定义数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iPhone和iPad之间使用NSUserActivity测试iOS 8.1切换功能.为此,我既尝试实现自己的解决方案,又尝试使用Apple的 PhotoHandoff 项目.但是,它不起作用.

I'm trying to test out the iOS 8.1 handoff feature with NSUserActivity between my iPhone and my iPad. For this, I tried both implementing my own solution, and to use Apple's PhotoHandoff project. However, it's not working.

如果我提供了webpageURL,则切换工作正常,但是当我尝试使用userDataaddUserInfoEntriesFromDictionary时,任何方法都无效,并且我一生无法弄清楚该抓捕的是什么数据工作.

If I provide a webpageURL, the handover works fine, but when I try to use userData or addUserInfoEntriesFromDictionary nothing works, and I can't for the life of me figure out what the catch is to make the data work.

示例代码:

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"com.company.MyTestApp.activity"];
activity.title = @"My Activity";
activity.userInfo = @ {};
//    activity.webpageURL = [NSURL URLWithString:@"http://google.com"];

self.userActivity = activity;

[self.userActivity becomeCurrent];
[self.userActivity addUserInfoEntriesFromDictionary:@ { @"nanananan": @[ @"totoro", @"monsters" ] }];

(我也无法使其与具有相应活动类型的Mac应用一起使用)

(I'm also unable to make it work with a Mac app with a corresponding activity type)

推荐答案

我希望您已经找到了解决方案,但是如果有人也偶然发现了这个问题,这是一个解决方案. (实际上与先前的答案没有太大不同)

I hope you found the solution already, but in case somebody stumbles upon this problem too, here is a solution. (Actually not very different from the previous answer)

在没有userInfo的情况下创建用户活动,它将被忽略:

Create user activity without userInfo, it will be ignored:

NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"..."];
activity.title = @"Test activity";
activity.delegate = self;
activity.needsSave = YES;

self.userActivity = activity;
[self.userActivity becomeCurrent];

强制委托对needSave事件做出反应:

Implement the delegate to react to needSave events:

- (void)userActivityWillSave:(NSUserActivity *)userActivity {
    userActivity.userInfo = @{ @"KEY" : @"VALUE" };
}

当needsSave设置为YES时,将调用此方法并更新userActivity.

When needsSave is set to YES this method will be called and userActivity will be updated.

希望这会有所帮助.

这篇关于NSUserActivity切换不适用于自定义数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆