기존 iOS 7 이상의 앱에 대해 오늘 확장 기능 (위젯이라고도 함)을 만들려고합니다. iOS Simulator에서는 모든 것이 잘 작동하지만 대부분의 경우 장치에서 위젯이 비어 있습니다. 헤더/이름 만 표시되고 내용은 표시되지 않습니다.투데이 위젯에 iOS 8 장치에 내용이 없음
비슷한 문제를 다루는 여러 스레드가 있지만 모두 Swift 응용 프로그램의 일부 init 문제와 관련이 있습니다. 스위프트가 아닌 Objectiv-c를 사용하고 있습니다.
이것은 내가 무슨 짓을 :
- 추가 내 응용 프로그램에 새로운 오늘 확장 대상입니다. 해당 구성표도 자동으로 생성되었습니다.
- 변경되지 않은 기본 위젯이 사용되는 경우에도 문제가 발생합니다. init 메소드를 추가하여 제대로 호출되었는지 확인합니다. 따라서 위젯은 기본
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
이 기록됩니다.
처음 장치를 실행할 때 예상대로 작동합니다. 오늘 화면이 나타나고 위젯이 표시됩니다. 내 위젯뿐만 아니라 내용이 없습니다.
그런 다음 엑스 코드는 다음과 같은 메시지를 보여줍니다
잃어버린 연결을 "시험 장치"- 연결에 "테스트 장치"를 복원하고 다시 "com.example.MyApp.Widget"를 실행하거나 경우 "com.example.MyApp.Widget"이 아직 실행중인 경우 에 디버그> 프로세스에 첨부> com.example.MyApp.Widget을 선택하여 첨부 할 수 있습니다.
아무 것도 기록되지 않았습니다. 연결이 끊어 졌기 때문에 기록되지 않습니다. 그런데 위젯이 비어있는 이유는 무엇입니까?
기기 로그를 조사했지만 충돌이 없습니다. 문제는 내 iPhone 6 (iOS 8.0) 및 iPad Air 2 (iOS 8.1)에서 동일합니다.
대단히 감사합니다!
iPhone 4S에서 정상적으로 작동하기 때문에 일반적으로 iOS 8에서는 문제가되지 않습니다. 문제는 전체 64 비트 프로세서가 포함 된 장치로, 5S 이상 및 iPad Air 및 최신 버전을 의미합니다. – Markus