![](/img/trans.png)
[英]iPhone: View/Close button click action on push notification message dialog
[英]Push notification and view button action[iphone sdk APNS]
我正在為iPhone開發支持推送通知的應用程序。 在我的應用程序中,我有兩個列表視圖(UITableView),第一個是類別列表,第二個是內容列表。 用戶單擊所需的類別,然后將顯示與該類別相關的內容,然后用戶將選擇內容,然后將其內容顯示在詳細視圖(通常為UIWebView)中。
推送通知已成功傳入我的應用程序。 我的要求是:-單擊“推送警報”的“查看”按鈕后,應用程序將直接顯示特定的詳細信息視圖(UIWebView)[省略類別和內容列表]。 我具有類別和內容的唯一ID。 因此,請您指導我如何將特定內容與“推送通知”相關聯並直接顯示該內容。
謝謝並恭祝安康。
嗨,
我已經解決了問題。 這就是我所做的。 當應用程序收到推送通知時,它將通知存儲在launchOptions NSDictionary中。
/* Push notification received when app is not running */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *params=[[launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"] objectForKey:@"contTag"];
if ([params length] > 0 ) {//app launch when VIEW button of push notification clicked
//do some processing
........
WebViewController *webViewController =
[[WebViewController alloc] initWithNibName:@"WebView" bundle:[NSBundle mainBundle]];
// Put your custom code
[[self navigationController ] pushViewController:webViewController animated:YES];
[window addSubview:navigationController.view];
/* Remote Notification Received while application was open. */
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"remote notification: %@",[userInfo description]);
NSString *contentsInfo = [userInfo objectForKey:@"contTag"];
NSLog(@"Received contents info : %@", contentsInfo);
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alert = [apsInfo objectForKey:@"alert"];
NSLog(@"Received Push Alert: %@", alert);
NSString *sound = [apsInfo objectForKey:@"sound"];
NSLog(@"Received Push Sound: %@", sound);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
//-----------------------APNS HANDLE----------------
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive){
NSLog(@" It is in active state");
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
}
else {
if ([contentsInfo length] > 0 ) {
// Do whatever u want for push notification handle
}
注意:這里contTag是在服務器端設置的密鑰,用於推送通知的有效負載。 U可以在服務器端設置任何鍵。
希望對身體有所幫助。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.