各位好,小弟最近遇到一个有关于推播的问题,
目前可以当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];
}