答案 0 :(得分:3)
是的,这可以使用pushkit静默通知。
收到推送工具包有效负载后,您必须安排本地通知。
您可以通过接受/拒绝乘车请求进行本地通知互动,并在API调用,SQLite等点击事件上做适当的事情。
请参阅下面的代码。我已按照VOIP通话功能起草了此功能,您可以根据自己的要求草拟。
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
// Process the received push
var arrTemp = [NSObject : AnyObject]()
arrTemp = payload.dictionaryPayload
let dict : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject>
if "IfUserHasLoggedInWithApp" // Check this flag then only proceed
{
if UIApplication.sharedApplication().applicationState == UIApplicationState.Background || UIApplication.sharedApplication().applicationState == UIApplicationState.Inactive
{
if "CheckForIncomingCall" // Check this flag to know incoming call or something else
{
var strTitle : String = dict["alertTitle"] as? String ?? ""
let strBody : String = dict["alertBody"] as? String ?? ""
strTitle = strTitle + "\n" + strBody
let notificationIncomingCall = UILocalNotification()
notificationIncomingCall.fireDate = NSDate(timeIntervalSinceNow: 1)
notificationIncomingCall.alertBody = strTitle
notificationIncomingCall.alertAction = "Open"
notificationIncomingCall.soundName = "SoundFile.mp3"
notificationIncomingCall.category = dict["category"] as? String ?? ""
notificationIncomingCall.userInfo = "As per payload you receive"
UIApplication.sharedApplication().scheduleLocalNotification(notificationIncomingCall)
}
else
{
// something else
}
}
}
}
请参阅有关pushkit集成和有效负载的更多信息。
https://github.com/hasyapanchasara/PushKit_SilentPushNotification