我收到此错误(应用程序在应用程序启动结束时应该有一个根视图控制器),我不知道为什么?我期待像令牌这样的东西:38c866dd bb323b39 ffa73487 5e157ee5 a85e0b7c e90d56e9 fe145bcc 6c2c594b。但不是:(
真的希望有人能解决这个问题。谢谢你,请你花时间在这上面。
代码如下。
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:viewController.view];
//[self.window setRootViewController:viewController];
[window makeKeyAndVisible];
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:@"Device Token=%@",deviceToken];
NSLog(str);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError: (NSError *)err {
NSString *str = [NSString stringWithFormat: @"Error: %@", err];
NSLog(str);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
答案 0 :(得分:1)
您的代码已过期。您不应该将视图控制器的视图添加为窗口的子视图。您应该将窗口的rootViewController
属性设置为视图控制器:
window.rootViewController = viewController;