我正在尝试为我现有的 iOS 7+ 应用程序创建 Today Extension(又名 Widget)。在 iOS 模拟器中,一切正常(大部分时间),但在我的设备上,小部件是空的——只显示标题/名称,但没有内容。
我发现有几个线程处理类似的问题,但它们都与 Swift 应用程序中的一些初始化问题有关。我使用的是 Objectiv-c 而不是 Swift。
这是我做的:
Hello World 标签。这是代码:
@interface TodayViewController () <NCWidgetProviding>
@end
@implementation TodayViewController
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self)
NSLog(@"initWithCoder");
return self;
}
- (id)init {
self = [super init];
if (self)
NSLog(@"init");
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
NSLog(@"initWithNibName");
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResultFailed
// If there's no update required, use NCUpdateResultNoData
// If there's an update, use NCUpdateResultNewData
completionHandler(NCUpdateResultNewData);
}
@end
选择小部件方案并在模拟器中运行它时,选择“今日”作为容器后,小部件正确显示。此外,还会记录 initWithCoder。
最初在设备上运行时,一切都按预期进行:出现今日屏幕并显示小部件。我的小部件也是如此,但没有任何内容。
然后 Xcode 显示以下消息:
Lost connection to "Test Device" - Restore the connection to "Test Device" and run "com.example.MyApp.Widget" again, or if "com.example.MyApp.Widget" is still running, you can attach to it by selecting Debug > Attach to Process > com.example.MyApp.Widget.
没有任何记录,我认为这是因为连接丢失。但是为什么小部件是空的?
我查看了设备日志,但没有崩溃。这个问题在我的 iPhone 6 (iOS 8.0) 和 iPad Air 2 (iOS 8.1) 上都是一样的
非常感谢!
最佳答案
经过几天的搜索,我终于找到了解决方案:
我的项目(小部件的包含应用程序)和小部件本身不包含 arm64 架构。作为Apple docs描述这不是一个有效的配置:
A containing app that links to an embedded framework must include the arm64 (iOS) or x86_64 (OS X) architecture build setting or it will be rejected by the App Store. (As described in Creating an App Extension, all app extensions must include the appropriate 64-bit architecture build setting.)
当缺少 x64 时,应用不仅会被拒绝,还会阻止小部件首先显示。
我将小部件添加到尚未针对 x64 配置的现有项目中,似乎相同的build设置已自动应用于小部件。如果 Xcode 会显示有关此问题的任何警告或提示,则可以避免很多工作......
我做了以下事情来解决这个问题:
Build Settings 选项卡并导航到 Architectures 部分。Architectures 设置为 Standard architectures (armv7, arm64)Valid Architectures 设置为 armv7 armv7s armv8 arm64Build Active Architectures Only 设置为 No此后小部件在模拟器和我的测试设备上都能正常工作。
关于ios - Today Widget 在 iOS 8 设备上没有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26551609/
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle