我目前正在开发一个接收推送通知的应用程序.我通过PHP页面100%全部工作.我的应用可以接收几种不同类型的推送通知.PHP处理这个并向我的应用程序发送不同的信息包,这些信息都被收到了.
但是,当用户"查看"通知并启动我的应用时,我显然想要采取与用户手动启动应用时不同的操作 - 最重要的是,根据推送通知类型执行不同的操作.我在结构上做得很好......
我的推送类型之一应该打开一个UIView,它与几个不同的服务器建立多个连接并来回协商数据.例如,当从主菜单触发时,此UIView工作正常 - 但是当我的推送通知触发此UIView出现时,套接字连接未按预期运行.
现在我的问题不是关于套接字,而是更多 - 如何调试这样的问题?从我所知道的(我相对较新)当应用程序从推送通知启动时,没有办法将该执行链接到调试器/控制台/等...我正在尝试使用调试代码进行调试时非常困难UIAlertViews,因为在各种服务器之间来回通信很多.
您对我的任何建议将不胜感激.
我在应用程序商店上有一个应用程序,它使用已过期的iOS配置文件(分发).此配置文件包含已过期的推送证书(并且不再出现在门户中).
问题1:有没有办法重新创建推送证书然后更新配置文件?(我的钥匙串上还有推送证书(已过期))?
问题2:我是否需要使用包含新推送证书的新配置文件将应用重新提交到应用商店?
由于推送证书已过期,我可能无法向应用的现有用户发送通知.
UIViewController屏幕上的当前需要通过设置徽标视图来响应来自APN的推送通知.但我怎么能得到UIViewControllerin方法application:didReceiveRemoteNotification:AppDelegate.m?
我尝试使用self.window.rootViewController获取当前显示UIViewController,它可能是一种UINavigationViewController或其他类型的视图控制器.我发现可以用来获取屏幕上的visibleViewController属性.但如果它不是,我该怎么办?UINavigationViewControllerUIViewControllerUINavigationViewController
任何帮助表示赞赏!相关代码如下.
AppDelegate.m
...
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//I would like to find out which view controller is on the screen here.
UIViewController *vc = [(UINavigationViewController *)self.window.rootViewController visibleViewController];
[vc performSelector:@selector(handleThePushNotification:) withObject:userInfo];
}
...
Run Code Online (Sandbox Code Playgroud)
ViewControllerA.m
- (void)handleThePushNotification:(NSDictionary *)userInfo{
//set some badge view here
}
Run Code Online (Sandbox Code Playgroud) 昨天谷歌在Google I/O上展示了基于新Firebase的新通知系统.我在Github上尝试了这个新的FCM(Firebase云消息传递)示例.
尽管我已声明了特定的drawable,但通知的图标始终是ic_launcher
为什么?以下是处理邮件的官方代码
public class AppFirebaseMessagingService extends FirebaseMessagingService {
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should …Run Code Online (Sandbox Code Playgroud) android push-notification googleio firebase firebase-cloud-messaging
我正在尝试让我的应用程序在Xcode 8.0中运行,并且遇到了错误.我知道这个代码在以前版本的swift中运行良好,但我假设在新版本中更改了代码.这是我正在尝试运行的代码:
let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.shared().registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)
我得到的错误是"参数标签"(forTypes:,categories :)'与任何可用的重载都不匹配"
是否有一个不同的命令,我可以尝试使其工作?
关于这个主题有很多stackoverflow线程,但我仍然没有找到一个好的解决方案.
如果应用程序不在后台,我可以launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]通过application:didFinishLaunchingWithOptions:电话查看它是否从通知中打开.
如果应用程序在后台,则所有帖子都建议使用application:didReceiveRemoteNotification:并检查应用程序状态.但是当我进行实验时(以及此API的名称建议),此方法在收到通知时被调用,而不是被点击.
所以问题是,如果应用程序启动然后背景化,并且您知道收到通知application:didReceiveNotification(此时application:didFinishLaunchWithOptions:不会触发),您如何知道用户是通过点击通知还是仅通过点击来恢复应用程序应用图标?因为如果用户点击了通知,则期望打开该通知中提到的页面.否则它不应该.
我可以handleActionWithIdentifier用于自定义操作通知,但这仅在轻触自定义操作按钮时触发,而不是在用户点击通知主体时触发.
谢谢.
编辑:
在阅读下面的一个答案之后,我想通过这种方式我可以澄清我的问题:
我们如何区分这两种情况:
(A)1.app转到后台; 2.收到通知; 3.用户点击通知; 4. app进入前台
(B)1.app转到后台; 2.收到通知; 3.用户忽略通知并稍后点击应用程序图标; 4. app进入前台
因为application:didReceiveRemoteNotification:在步骤2中两种情况都被触发.
或者,应application:didReceiveRemoteNotification:仅在步骤3中针对(A)触发,但我以某种方式将我的应用程序配置错误,所以我在第2步看到它?
我正在我的应用程序中实现Google Cloud Messaging.服务器代码还没有准备好,在我的环境中由于一些防火墙限制,我无法为推送通知部署测试服务器.我正在寻找的是一个在线服务器,它会向我的设备发送一些测试通知来测试我的客户端实现.
android server-push push-notification android-notifications google-cloud-messaging
如果没有设备需要轮询服务器,iOS"推送"通知如何传递到特定设备?
例如,假设我在Facebook上收到了一条新消息.Facebook通知Apple我的设备应该收到通知.但Apple如何知道将消息推送到哪个设备/ IP?
在WWDC 2013的"多任务新功能"演示中,有一个关于静音推送通知的部分.看起来很简单.根据演示文稿,如果您将APS有效负载仅发送到内容可用设置为1,则不会通知用户该通知.
// A. This doesn't work
{
aps: {
content-available: 1
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试显示,这不起作用,因为没有收到推送.但是,如果我包含声音属性但排除了alert属性,它就会起作用(虽然不再是静音).
// B. This works
{
aps: {
content-available: 1,
sound: "default"
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改声音属性以播放静音,我可以模仿静音.
// C. This works too.
{
aps: {
content-available: 1,
sound: "silence.wav"
}
}
Run Code Online (Sandbox Code Playgroud)
有人知道吗:
提前致谢.
编辑更多信息
对于A,应用程序的状态无关紧要.从未收到通知.
看起来B和C只有在将属性和值括在引号中时才有效,如下所示.
{"aps":{"content-available": 1, "sound":"silent.wav"}}
Run Code Online (Sandbox Code Playgroud)
并且通知到达应用程序:didReceiveRemoteNotification:fetchCompletionHandler:无论状态如何.
在Google Cloud Messaging的文档中,它指出:
Android应用程序应该存储此ID以供以后使用(例如,如果已经注册,则检查onCreate()).请注意,Google可能会定期刷新注册ID,因此您应该设计Android应用程序,并了解可能会多次调用com.google.android.c2dm.intent.REGISTRATION意图.您的Android应用程序需要能够做出相应的响应.
我使用以下代码注册我的设备:
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regID = gcm.register(senderID);
Run Code Online (Sandbox Code Playgroud)
GoogleCloudMessaging类封装了注册过程.那么我想如何处理com.google.android.c2dm.intent.REGISTRATION,因为处理是由GoogleCloudMessaging类在内部完成的?