【发布时间】:2015-10-29 14:08:32
【问题描述】:
我是初学者用 swift 写关于 IOS 推送的文章。它在应用程序在前台运行时有效,但在应用程序在后台或关闭时无效。 顺便说一句,当应用程序处于后台或关闭时,我可以通过 APNS.newPayload().alertBody 接收警报消息。 非常感谢您的帮助。
下面是我的服务器和ios代码。
iOS 代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Recived: \(userInfo)")
var receiveMsg = userInfo["key1"] as! String
print("receiveMsg = \(receiveMsg)")
}
服务器代码
ApnsService service =
APNS.newService()
.withCert("ooxx.p12","")
.withSandboxDestination()
.build();
String payload = APNS.newPayload().customField("key1", "M;senderGCMID5;senderUserID5;userName5;userMessage5").build();
String token = "token";
service.push(token, payload);
我已经阅读了一些关于这个主题的问题,但我无法解决这个问题。
我尝试了下面iOS代码中的其他功能,但它不起作用。
APNS push working in foreground but not background
我不知道如何实现。你能教我吗?非常感谢
func application
(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
var receiveMsg = userInfo["key1"] as! String
print("receiveMsg = \(receiveMsg)")
}
感谢 pralthom 的帮助,我通过设置 content value = 1 来解决这个问题。
【问题讨论】:
标签: ios background push-notification javapns