I am beginner write about IOS push with swift. It works when app is running in foreground but not work while app in background or close. By the way, I can receive alert message by APNS.newPayload().alertBody when app is in background or close. Thank u much for help.
Below is my server and ios code.
iOScode
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print("Recived: \(userInfo)")
var receiveMsg = userInfo["key1"] as! String
print("receiveMsg = \(receiveMsg)")
}
Server Code
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);
I have read some question about this topic, but I can not solve this problem.
I have tried the other function in iOS code like below, and it doesn't work.
APNS push working in foreground but not background
I don't know how to implement. Can u teach me ? thanks much
func application
(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
var receiveMsg = userInfo["key1"] as! String
print("receiveMsg = \(receiveMsg)")
}
thank pralthom for helping, I sovle the problem by setting content value = 1.