はい、これはプッシュキットのサイレント通知で可能です。
プッシュキットのペイロードを受け取ったら、ローカル通知をスケジュールする必要があります。
ライドリクエストの承認/拒否を使用してローカル通知をインタラクティブにし、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
}
}
}
}
プッシュキットの統合とペイロードについて詳しくは、こちらをご覧ください。
https://github.com/hasyapanchasara/PushKit_SilentPushNotification
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加