- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在使用我的应用程序中的 mapItem 实现 NSUserActivity 时遇到了一些问题。
我想要的只是能够在应用程序切换器中使用“获取路线”建议,就像 Foursquare 所做的那样:
我在我的 viewDidLoad
方法中使用以下代码,在显示我要注册的位置(酒吧)的 View Controller 中。
NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:@"co.pubmapper.ViewPub"];
CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(self.pub.lat, self.pub.lng);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coords];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:self.pub.name];
activity.mapItem = mapItem;
// not sure any of these are necessary for my use case
[activity setEligibleForSearch:YES];
[activity setEligibleForHandoff:YES];
[activity setEligibleForPublicIndexing:YES];
[activity becomeCurrent];
运行时,我在控制台中看到以下内容:
[main] sendUserActivityToServer, called on activity C626E4B1-ADF8-49D8-80FB-C773DB71243D after it had been invalidated, so doing nothing.
这表明我的 activity
项目由于某种原因立即失效。我添加了以下内容来设置 expirationDate
但仍然在控制台中收到相同的消息。
activity.expirationDate = [NSDate distantFuture];
据我所知,我已经遵循了此处文档中的所有内容 https://developer.apple.com/reference/foundation/nsuseractivity?language=objc
我还将我的事件类型添加到 NSUserActivityTypes
,尽管我认为这只是启动我的应用程序和接收事件对象所必需的,这不是我现在关心的.
已解决:根据下面@raidfive 的正确答案,activity
现在是一个具有强引用的类属性:
@property (strong) NSUserActivity *activity;
...
[_activity becomeCurrent];
最佳答案
我不确定这是否适用于 mapItem
类型,但文档提到:
Your app must maintain a strong reference to any activity objects that you use for search results.
因此,您可能需要将 activity
存储为类级变量。
关于ios - 指示无效的 NSUserActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41524771/
我在使用我的应用程序中的 mapItem 实现 NSUserActivity 时遇到了一些问题。 我想要的只是能够在应用程序切换器中使用“获取路线”建议,就像 Foursquare 所做的那样: 我在
我正在尝试使用 NSUserActivity 在我的 iPhone 和 iPad 之间测试 iOS 8.1 切换功能。为此,我尝试既实现自己的解决方案,又使用 Apple 的 PhotoHandoff
在 iOS 9 中,NSUserActivities 可以与 Siri 一起使用,例如,“Siri,请在一小时内提醒我”,在她知道“THIS”是什么的上下文的情况下创建提醒。有没有办法以编程方式执行此
我有一个关于 NSUserActivity 的 userInfo 属性的快速问题。 NSString *activity = @"com.test.activity"; NSUserActivity
以下是我试图实现的代码,使应用程序事件和状态可搜索但无法在 iOS 搜索中显示 NSUserActivity *userActivity = [[NSUserActivity alloc]initWi
我正在努力思考 NSUserActivity,但我并不完全确定如何正确使用它们。我已经像这样正确设置了我的 NSUserActivity: let attributeSet = CSSearchabl
我正在尝试使用通用链接从应用程序 A 打开应用程序 B,如下所示: @IBAction func openButtonPressed(_ sender: Any) { if let appUR
这就是我注册 UserActivity 的方式。 我得到了捷径并且功能有效。 但是我得到的应用程序图标是缩略图,而不是我设置的图标, func registerUserActivity(compone
我试图让我的 NSUserActivity 被 iOS 中 Spotlight 中的私有(private)索引索引。我已按照 Apple's Index Activities and Navigati
我正在使用 NSUserActivities 实现 iOS9 搜索索引。根据文档 NSUserActivity应该有一个名为 contentAttributeSet 的属性,用于向搜索项添加更多内容。
我有一个应用程序,您可以在其中找到我们大学的员工,并通过电子邮件与他们联系。当你找到某人并查看详细信息时,将创建一个 NSUserActivity: if (SYSTEM_VERSION_GREATE
我正在尝试将我自己的事件添加到 osx 10.11 上的 Spotlight 搜索结果中。但经过多次尝试,我无法通过关键字搜索或标题搜索进入 Spotlight 搜索结果。 { self.us
所以目前正在测试一些 ios9 beta 功能,但是 NSUserActivity 类已经有一段时间了,它用于切换。 基本上就是这样。当应用启动 NSUserActivity 时,我可以看到 laun
我阅读了一些教程,发现 NSUserActivity 用于用户进行事件时的索引信息,Core Spotlight 用于索引应用程序中的一组内容数据。 使用 NSUserActivity var act
我正在使用 NSUserActivity 定义应用程序函数,因此它会出现在 Spotlight 和 Siri 快捷方式中: let activity = NSUserActivity(activity
在WWDC2015看iOS9搜索API的视频时,有一个demo是这样的: var activity:NSUserActivity = NSUserActivity(activityType:"com.
我同时使用 NSUserActivity 和 Core Spotlight 来索引我应用程序中的内容。我使用 Core Spotlight 的原因是因为我想在用户访问(打开)它之前索引这些内容。 我面
我正在快速实现 CallKit,我在直接从最近的日志中进行调用时遇到了 NSUserActivity 问题。 在最近的日志中点击我的应用条目时,我的应用正在启动,但 AppDelegate 的任何方法
使用 Xcode 10(测试版 6)我可以毫无问题地编写和运行以下代码: import Intents func test() { let activity = NSUserActivity(
我已经在我们的应用程序中实现了 Handoff,当应用程序在前台或后台运行时,它可以很好地用于 Web 到应用程序的切换,反之亦然。 但是,如果应用未运行,那么如果用户从 Web 到应用切换启动应用,
我是一名优秀的程序员,十分优秀!