我知道这将是一个简单的解决方案,但由于某种原因,当我尝试使用其他解决方案解决我的问题时,它只是不起作用。在我的应用程序中,我设置了推送通知,并且我试图设置tabBarItem
从通知打开应用程序时打开应用程序的功能。这是我到目前为止的代码,请告诉我我是否使用了正确的方法。我不是很有经验,AppDelegate.m
所以如果完全错误,请原谅我。
AppDelegate.m
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate,CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,readonly) UITabBar *tabBar;
@property(nonatomic,strong) UITabBarController *tabBarController;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
return YES;
}
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo{
/* this works just fine*/
NSLog(@"opening from a notification!!");
/*this is what doesnt work at all*/
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController ];
self.tabBarController.selectedIndex = 3;
/*also when i do nslog the selectedIndex it gives me this value "2147483647"*/
NSLog(@"%i is the tabbar item",tabBarController.selectedIndex);
}