2012-04-27 26 views
2

iOS 5の通知を正常に受信しました。通知センターでプッシュ通知をスワイプまたはタップすると、特定のビューにユーザーを送信できるようにします。プッシュ通知からのプッシュ表示

View Controller(view)ユーザーが私のアプリケーションの開始に反対するようにしたいのは、 "groceryStoreViewController"です。私はこれがdidFinishLaunchingWithOptionsまたはdidReceiveRemoteNotificationで行われているが、わかりません。

誰かがこれを行う方法を知っていれば、本当に闘争だったので、私は本当にそれを感謝します。

おかげ

EDIT

だから問題は、私は、ユーザーが通知をタップしたときに、特定のビューコントローラを開くことにしたいが、私はまたUITabBarのままにしておきたいということです。私はこれを成功裏に実行することができませんでした。それは、私が信じているサブビューを表示することと私が関係しています。あなたの考えを伝えてくれてありがとう。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

self.tabBarItem = [[[UITabBarItem alloc] init] autorelease]; 

exploreViewController *view1 = [[exploreViewController alloc] initWithNibName:@"exploreViewController" bundle:nil]; 
view1.title= @"Explore"; 

Upcoming *view2 = [[Upcoming alloc] initWithNibName:@"Upcoming" bundle:nil]; 
view2.title = @"Upcoming"; 

TipsViewController *view3 = [[TipsViewController alloc] initWithNibName:@"TipsView" bundle:nil]; 
view3.title = @"Tips"; 

UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:view1]; 
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:view2]; 
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:view3]; 

[view1 release]; 
[view2 release]; 
[view3 release]; 

self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nil]; 
self.tabBarItem = [[[UITabBarItem alloc] init] autorelease]; 

[nav1 release]; 
[nav2 release]; 
[nav3 release]; 


if (launchOptions != nil) 
{ 
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]; 
NSLog(@"Launched from push notification"); 
//Accept push notification when app is not open 
if (remoteNotif) {  

NSDictionary *alertBody = [remoteNotif objectForKey:@"loc-key"]; 

self.window.rootViewController = nav2; //this is what I want displayed when tapped but also maintain tab bar controller 
    [window addSubview:tabBarController.view]; 
    [window makeKeyAndVisible]; 

    } 
} 
else { 

    //Go here if just loading up normally without push 
    [window addSubview:tabBarController.view]; 
    [window makeKeyAndVisible]; 

} 
    return YES; 

} 
+0

質問は明確に定義されていません。! –

+3

@hp iOSコーダー:ここにスタックしているすべてのユーザーが英語を話せるわけではありません。だから親切にして、それを撃つ.. – filou

答えて

3

didFinishLaunchingWithOptions:の方法で行われます。通知のためにアプリが起動したかどうかをチェックし、適切なviewControllerを表示するように設定できます。

ような何か:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    // other stuff 

    if (launchOptions != nil) { 
     NSLog(@"Launched from push notification"); 
     NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; 
     // Do something with the notification dictionary 
     self.myViewController = [LaunchFromNotificationViewController alloc] init]; 
    } else { 
     self.myViewController = [OrdinaryLaunchViewController alloc] init]; 
    } 

    self.window.rootViewController = self.myViewController; 
    [self.windows makeKeyAndVisible]; 
    return YES; 
} 
+0

あなたは例を挙げてもいいですか?たくさんのことを意味するだろう。ありがとう –

+0

@AlexGの例が追加されました。 – jcm

+0

@ jcm:新しいストーリーボード機能でコードを使用しようとしました。ビューへの代表者は動作しません..あなたはストーリーボードでの経験はありますか? – filou