![](/img/trans.png)
[英]Does iOS state preservation/restoration survive app uninstall and reinstall?
[英]iOs open app from preservation state
我的应用程序具有2个主要功能:
在启动应用程序期间,下载数据的初始部分(与服务器同步日历,从服务器获取新消息)。 我在该过程中使用了启动画面。
当应用进入保存状态时,用户可以使用聊天中的推送消息打开应用。
我已覆盖
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:[PurchaseHelper sharedInstance]];
[Parse setApplicationId:kPLParseAppId clientKey:kPLParseClientId];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[Crashlytics startWithAPIKey:@"mykey"];
// social networks API
[PFFacebookUtils initializeFacebook];
[[OkClient sharedInstance] initializeOdnoklassniki];
[[VkClient sharedInstance] initializeVk];
// load magical record support
[MagicalRecord setupCoreDataStackWithStoreNamed:@"Model.sqlite"];
// subscribe to notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogin) name:kPLUserDidLoginNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogout) name:kPLUserDidLogoutNotification object:nil];
// subscribe to pushes
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound];
UIColor *greenColor = [UIColor colorWithRed:111 green:221 blue:215 andAlpha:255];
if([[UINavigationBar appearance] respondsToSelector:@selector(barTintColor)]) {
// iOS7
[UINavigationBar appearance].barTintColor = greenColor;
} else {
// older
[UINavigationBar appearance].tintColor = greenColor;
}
[[UINavigationBar appearance] setTitleTextAttributes:
@{NSFontAttributeName : [UIFont fontWithName:@"Circe-Regular" size:16.],
NSForegroundColorAttributeName: [UIColor blackColor]}];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Circe-Regular" size:16.], NSForegroundColorAttributeName: [UIColor blackColor]} forState:UIControlStateNormal];
// if app is started from push open chat
if (launchOptions != nil) {
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil) {
ChatModel *chat = [self handlePushNotification:dictionary];
[self launchChat:chat];
}
}
// update purchase data if user is authenticated
if ([[UserApiClient sharedInstance] isAuthenticated]) {
[self updatePurchaseData];
}
// add styles
[self addStyle];
return YES;
}
而launchChat是:
- (void) launchChat:(ChatModel *) chat {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// reveal controller
UIViewController *revealController = [storyboard instantiateViewControllerWithIdentifier:@"AuxController"];
ChatViewController *chatController = [storyboard instantiateViewControllerWithIdentifier:@"chatVC"];
chatController.chatModelId = chat.objectID;
self.window.rootViewController = revealController;
for (UIViewController *controller in [revealController childViewControllers]){
if ([controller isKindOfClass:[UINavigationController class]]) {
UINavigationController *navController = (UINavigationController *) controller;
[navController pushViewController:chatController animated:YES];
break;
}
}
}
但是不幸的是,相反,我得到了常规的启动画面。 我的错误在哪里?
我猜您将需要替换window
而不仅仅是rootViewController
。 我不能说我实际上是用情节提要板完成的,所以有点猜测...
如果不起作用,则需要在情节rootViewController
中删除初始的视图控制器名称,并针对所有情况在代码中配置rootViewController
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.