[英]Push notification alert view action?
我有一個iPhone應用程序,其中我正在將推送通知作為Alertview。當我的應用程序處於后台狀態時,推送通知即將到來,當我單擊它或解鎖手機時,它將直接進入該應用程序我將其保留為前景色的狀態。我在警報中添加了一個單擊視圖按鈕的操作,該操作將轉到另一個視圖控制器。當我單擊通知時,我想輸入該應用程序。我需要顯示alertview,當單擊視圖按鈕時,我需要執行操作。任何人都可以幫助我實現這一點。這是我的代碼段`-
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//check application in forground or background
if(application.applicationState == UIApplicationStateActive)
{
//NSLog(@"FOreGround");
//NSLog(@"and Showing %@",userInfo)
}
else
{
NSDictionary *curDict= [userInfo objectForKey:@"aps"];
UIAlertView *connectionAlert = [[UIAlertView alloc] initWithTitle:@"app" message:[NSString stringWithFormat:@"%@",[curDict objectForKey:@"alert"]] delegate:self cancelButtonTitle:@"View" otherButtonTitles:@"Cancel",nil];
[connectionAlert show];
[connectionAlert release];
[UIApplication sharedApplication].applicationIconBadgeNumber =[[curDict objectForKey:@"badge"] intValue];
}
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"applicationWillEnterForeground");
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"View"])
{
NSArray *mycontrollers = self.tabBarController.viewControllers;
NSLog(@"%@",mycontrollers);
[[mycontrollers objectAtIndex:0] popToRootViewControllerAnimated:NO];
mycontrollers = nil;
tabBarController.selectedIndex = 0;
}
}
您向用戶顯示UIAlertView。收到通知后,將調用didReceiveRemoteNotification:函數。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"userInfo :%@",userInfo);
NSString* msg = [userInfo valueForKey:@"aps"];
if (self._VCObj.isViewLoaded && self._VCObj.view.window) {
// viewController is visible don't show.
}
else { // viewController is not visible
[[[UIAlertView alloc]initWithTitle:@"Title" message:msg delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil] show];
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.