各位好,小弟最近遇到一個有關於推播的問題,
目前可以當APP在前台收到推波時將一個viewcontroller的view addsubview上去,
也可以在背景或是尚未執行的時候點推波訊息,能夠順利打開app並將view展現出來,
但只要使用者在背景或是尚未開啟app的時候是直接點選桌面上的icon,
view將不會被貼上去,想請問是這做法不可行還是我還沒找到方向呢!?
目前部分code如下
ps.目前還有一個問題是BadgeNumber的問題,如何讓收到推波的時候+1 並只要有開啟或
正在開啟的時number就為0呢)
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *remoteNotif = [launchOptions objectForKey:
UIApplicationLaunchOptionsRemoteNotificationKey];
// Accept push notification when app is not open
if (remoteNotif) {
[self handleRemoteNotification:application
didReceiveRemoteNotification:remoteNotif];
}
}
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
if([[userInfo objectForKey:@"aps"] objectForKey:@"alert"]!=NULL){
NSString *alertbody = [[userInfo objectForKey:@"aps"]
objectForKey:@"alert"];
UIStoryboard* mainStoryboard = [UIStoryboard
storyboardWithName:@"Main" bundle: nil];
AlertCustumViewController * view1 = [mainStoryboard
instantiateViewControllerWithIdentifier:@"alert"];
[self.window addSubview:view1.view];
application.applicationIconBadgeNumber =
application.applicationIconBadgeNumber+1;
}
}
-(void)handleRemoteNotification:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
bundle: nil];
AlertCustumViewController * view1 = [mainStoryboard
instantiateViewControllerWithIdentifier:@"alert"];
[self.window addSubview:view1.view];
}