[問題] 請問推波的判定

作者: larry122 (larry122)   2016-07-14 00:35:13
各位好,小弟最近遇到一個有關於推播的問題,
目前可以當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];
}
作者: howdiun (Howdiun)   2016-07-14 09:19:00
像line點推播會開那一頁,直接點icon就不會,大家都一樣
作者: LFimi   2016-07-14 09:27:00
開啟app之後將applicationIconBadgeNumber設為0就好
作者: larry122 (larry122)   2016-07-14 10:13:00
感謝 我上班只能手機回文 目前對badge想法是數字是再didReviceRemoteNotification +1 然後didFinishLauchingwithOption歸0 我來測看看
作者: songooo (songooo)   2016-07-14 11:25:00
可考慮在applicationWillEnterForeground歸0可能要把原本app就在背景時的狀況考慮進去
作者: larry122 (larry122)   2016-07-14 12:07:00
感謝樓上 目前是用becomeactive歸0 下午測試您的方法看看所以點icon目前似乎是無解
作者: jazzter (阿里巴巴你媽媽)   2016-07-14 14:20:00
應該說,你如果要改變app進入時的狀態是不能單仰賴推播的,它本身就不是個可靠的data source,建議你如真有這需求用,改用其它方式手機推文斷句很亂歹勢
作者: larry122 (larry122)   2016-07-14 15:08:00
了解 感謝您 我也是手機推文亂斷行

Links booklink

Contact Us: admin [ a t ] ucptt.com