iOS的推送通知的问题 [英] iOS Push notification issue

查看:244
本文介绍了iOS的推送通知的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做其中的项目推送通知功能是主要特征之一。结果
它工作正常,当我在应用程序,我收到通知并处理通知。

但问题是,当我在后台和通知接收我看徽章在我的应用程序图标
当我点击该图标我的应用程序正在启动,但 didReceiveRemoteNotification 方法不叫,所以我不能处理的通知。

和另外一个问题是,有些时候,它显示了在设备通知列表有的时候它也没通知消息。

当我在我的应用程序通过点击通知列表项的 didReceiveRemoteNotification 通话进入,我能够成功处理通知。
我写下面code在 didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions方法

 的NSDictionary * remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
如果(remoteNotif!=无)
{
    的NSLog(@didFinishLaunchingWithOptions \\ nNotification收到:\\ n%@,remoteNotif);    notificationData = [[NSDictionary的页头] initWithDictionary:remoteNotif];
    [notif saveNotification:remoteNotif];
}

帮我解决这个问题。
先谢谢了。


解决方案

从苹果公司的<一个href=\"http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html\"相对=nofollow>本地和推送通知编程指南


  

处理本地和远程通知


  
  

让我们回顾一下可能出现的情况时,系统提供本地
  通知或应用程序的远程通知。


  
  

      
  1. 当应用程序没有在前台运行的通知交付。


      
      

    在这种情况下,系统presents该通知,显示一个
      警报,徽章图标,也许播放声音。


      
      

    由于$ P $的结果psented通知,用户点击的动作
      警报或抽头(或点击)按钮的应用程序图标。


      
      

    如果操作按钮被窃听(运行iOS的设备上),系统
      启动应用程序和应用程序调用其委托的
      的application:didFinishLaunchingWithOptions:方法(如果
      实施);它通过在通知有效载荷(用于远程
      通知)或本地通知对象(本地
      通知)。


      
      

    如果应用程序图标运行iOS的设备上拍了拍,应用程序调用相同的方法,但配料没有信息
      有关通知
    即可。如果应用程序图标被点击一
      运行OS X的计算机,应用程序调用委托的
      的applicationDidFinishLaunching:方法,其中委托可以
      取得远程通知的有效载荷。


  2.   
  3. 当应用程序在前台运行的通知交付。


      
      

    应用程序调用其委托的
      应用程序:didReceiveRemoteNotification:方法(用于远程
      通知)或应用程序:didReceiveLocalNotification:方法
      (用于本地通知),并将在通知有效载荷或
      本地通知对象。


  4.   

所以你的情况,当应用程序在后台运行,当您单击通知/警报,操作系统将您的应用程序到前台。所以它陷入第二点。

您可以实施应用程序:didReceiveRemoteNotification:方法来获取通知的有效载荷,如果操作按钮被窃听。但是,当应用程序图标pssed代替动作信息$ P $,通知有效载荷不与方法转发。你唯一的选择是与您的服务器,并同步数据。毕竟根据苹果的政策,推送通知只是告诉有在服务器上的数据,你需要连接到服务器并获取数据的两种方式。

I am doing a project in which push notification feature is one of the key feature.
It is working fine when I am in the app, I receive notification and handle that notification.

But the issue is when I am in background and notification receives I see badge on my app icon and when I click on the icon my app is launching but the didReceiveRemoteNotification method is not called so I am unable to handle that notification.

And another issue is some times it shows the notification message in device notification list and some times it didn't .

When I am entering in my app through clicking on notification list item the didReceiveRemoteNotification calls and I am successfully able to handle notification. I write following code in didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method

NSDictionary* remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotif != nil)
{
    NSLog(@"didFinishLaunchingWithOptions\nNotification recieved:\n%@",remoteNotif);

    notificationData=[[NSDictionary alloc]initWithDictionary:remoteNotif];
    [notif saveNotification:remoteNotif];
}

Help me to resolve this . Thanks in advance.

解决方案

From Apple's Local And Push Notification programming guide

Handling Local and Remote Notifications

Let’s review the possible scenarios when the system delivers a local notification or a remote notification for an application.

  1. The notification is delivered when the application isn’t running in the foreground.

    In this case, the system presents the notification, displaying an alert, badging an icon, perhaps playing a sound.

    As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon.

    If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

    If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification . If the application icon is clicked on a computer running OS X, the application calls the delegate’s applicationDidFinishLaunching: method in which the delegate can obtain the remote-notification payload.

  2. The notification is delivered when the application is running in the foreground.

    The application calls its delegate’s application:didReceiveRemoteNotification: method (for remote notifications) or application:didReceiveLocalNotification: method (for local notifications) and passes in the notification payload or the local-notification object.

So in your case, when application is running in background, and when you click the notification/alert, operating system brings your app into foreground. So it falls under second point.

You can implement application:didReceiveRemoteNotification: method to get the notification payload, if action button is tapped. But when the application icon is pressed instead of action message, the notification payload is not forwarded with the method. Your only option is to contact your server and sync the data. After all as per Apple's policy, push notification only tells that there is data on server, and either way you need to connect to server and get the data.

这篇关于iOS的推送通知的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆