And*_*ord 6 iphone widget objective-c ios ios8-today-widget
我正在尝试为我现有的iOS 7+应用程序创建Today Extension(aka Widget).在iOS模拟器中一切正常(大部分时间),但在我的设备上,小部件是空的 - 只显示标题/名称但没有内容.
我发现有几个线程处理类似的问题,但它们都与Swift应用程序中的一些init问题有关.我使用的是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
Run Code Online (Sandbox Code Playgroud)
选择窗口小部件方案并在模拟器中运行时,在选择"今天"作为容器后,窗口小部件会正确显示.另外initWithCoder记录.
在设备上运行时,一切都按预期工作:今日屏幕出现并显示小部件.我的小部件也是,但没有任何内容.
然后Xcode显示以下消息:
丢失与"测试设备"的连接 - 恢复与"测试设备"的连接并再次运行"com.example.MyApp.Widget",或者如果"com.example.MyApp.Widget"仍在运行,则可以通过选择Debug> Attach to Process> com.example.MyApp.Widget.
没有记录,我认为这是因为连接丢失.但为什么小部件是空的?
我查看了设备日志,但没有崩溃.问题在我的iPhone 6(iOS 8.0)和iPad Air 2(iOS 8.1)上是一样的
非常感谢你!
经过几天的查找,终于找到了解决方案:
我的项目(小部件的包含应用程序)和小部件本身不包括arm64架构。正如Apple 文档所描述的,这不是有效的配置:
链接到嵌入式框架的包含应用程序必须包含 arm64 (iOS) 或 x86_64 (OS X) 架构构建设置,否则将被 App Store 拒绝。(如创建应用程序扩展中所述,所有应用程序扩展必须包含适当的 64 位架构构建设置。)
当 x64 缺失时,应用程序不仅会被拒绝,还会阻止小部件首先显示。
我将该小部件添加到尚未配置为 x64 的现有项目中,并且似乎相同的构建设置已自动应用于该小部件。如果 Xcode 显示有关此问题的任何警告或提示,则可以避免很多工作......
我执行了以下操作来解决该问题:
Build Settings选项卡并导航到该Architectures部分。ArchitecturesStandard architectures (armv7, arm64)Valid Architecturesarmv7 armv7s armv8 arm64Build Active Architectures OnlyNo之后,该小部件在模拟器和我的测试设备上都能正常工作。
| 归档时间: |
|
| 查看次数: |
2054 次 |
| 最近记录: |