ios设备中未接收到Voip推送

ios设备中未接收到Voip推送,ios,apple-push-notifications,voip,Ios,Apple Push Notifications,Voip,我想为我的应用程序添加voip推送支持。我跟着楼梯走。从huston发送推送时,会显示“1推送通知已成功发送”。我使用amazon sns尝试了同样的方法,它说推送成功发布,但我没有看到在注册表委托处收到推送,即didReceiveIncomingPushWithPayload。我使用voip分发配置文件尝试了这一点。 任何帮助都将不胜感激。是遵循VOIP步骤的一个链接 当您收到任何voip通知时,didReceiveIncomingPushWithPayloadget invoke。您可以从那

我想为我的应用程序添加voip推送支持。我跟着楼梯走。从huston发送推送时,会显示“1推送通知已成功发送”。我使用amazon sns尝试了同样的方法,它说推送成功发布,但我没有看到在注册表委托处收到推送,即didReceiveIncomingPushWithPayload。我使用voip分发配置文件尝试了这一点。 任何帮助都将不胜感激。

是遵循VOIP步骤的一个链接

当您收到任何voip通知时,didReceiveIncomingPushWithPayloadget invoke。您可以从那里使用本地通知通知用户。

参考

目标C和Swift代码都存在

只需检查证书、代码和发送voip(静默)推送通知

import UIKit
import PushKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


    let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
    application.registerForRemoteNotificationTypes(types)

    self.PushKitRegistration()

    return true
}

//MARK: - PushKitRegistration

func PushKitRegistration()
{

    let mainQueue = dispatch_get_main_queue()
    // Create a push registry object
    if #available(iOS 8.0, *) {

        let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)

        // Set the registry's delegate to self

        voipRegistry.delegate = self

        // Set the push type to VoIP

        voipRegistry.desiredPushTypes = [PKPushTypeVoIP]

    } else {
        // Fallback on earlier versions
    }


}


@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
    // Register VoIP push token (a property of PKPushCredentials) with server

    let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes),
        count: credentials.token.length).map { String(format: "%02x", $0) }.joinWithSeparator("")

    print(hexString)


}


@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
    // Process the received push


}


func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}
导入UIKit
导入推送套件
@UIApplicationMain
类AppDelegate:UIResponder、UIApplicationDelegate、PKPushRegistryDelegate{
变量窗口:UIWindow?
func应用程序(应用程序:UIApplication,didFinishLaunchingWithOptions启动选项:[NSObject:AnyObject]?)->Bool{
let类型:UIRemoteNotificationType=[.Alert、.Badge、.Sound]
application.registerForRemoteNotificationTypes(类型)
self.pushkit注册()
返回真值
}
//马克:注册
func pushkit注册()
{
让mainQueue=dispatch\u get\u main\u queue()
//创建推送注册表对象
如果可用(iOS 8.0,*){
让voipRegistry:PKPushRegistry=PKPushRegistry(队列:mainQueue)
//将注册表的委托设置为self
voipRegistry.delegate=self
//将推送类型设置为VoIP
voipRegistry.desiredPushTypes=[PKPushTypeVoIP]
}否则{
//对早期版本的回退
}
}
@可用(iOS 8.0,*)
func pushRegistry(注册表:PKPushRegistry!,didUpdatePushCredentials:PKPushCredentials!,forType:String!){
//向服务器注册VoIP推送令牌(PKPushCredentials的属性)
让hexString:String=UnsafeBufferPointer(开始:UnsafePointer(credentials.token.bytes)),
计数:credentials.token.length).map{String(格式:'%02x',$0)}.joinWithSeparator(“”)
打印(十六进制字符串)
}
@可用(iOS 8.0,*)
func pushRegistry(注册表:PKPushRegistry!,didReceiveIncomingPushWithPayload:PKPushPayload!,forType:String!){
//处理接收到的推送
}
func应用程序WillResignActive(应用程序:UIApplication){
//当应用程序即将从活动状态移动到非活动状态时发送。这可能发生在某些类型的临时中断(如来电或短信)或用户退出应用程序并开始转换到后台状态时。
//使用此方法暂停正在进行的任务、禁用计时器和降低OpenGL ES帧速率。游戏应使用此方法暂停游戏。
}
func应用程序标识符背景(应用程序:UIApplication){
//使用此方法释放共享资源、保存用户数据、使计时器无效,并存储足够的应用程序状态信息,以便在应用程序稍后终止时将其恢复到当前状态。
//如果您的应用程序支持后台执行,则会调用此方法而不是applicationWillTerminate:当用户退出时。
}
func应用程序将进入前台(应用程序:UIApplication){
//作为从后台转换到非活动状态的一部分调用;在这里,您可以撤消进入后台时所做的许多更改。
}
func ApplicationIDBecMeactive(应用程序:UIApplication){
//重新启动应用程序处于非活动状态时暂停(或尚未启动)的所有任务。如果应用程序以前位于后台,可以选择刷新用户界面。
}
func应用程序将终止(应用程序:UIApplication){
//当应用程序即将终止时调用。如果合适,请保存数据。另请参阅ApplicationIdentinterBackground:。
}
}
有一个快乐的编码。

可能的原因:

  • 您的.pem证书可能有误
  • 你的回答可能是错的
  • 您的设备id可能有误
  • 注意:使用bundleid附加.voip以发送voip推送通知(例如:bundleid.voip)

    以下是一个可行的voip推送通知示例:

    <?php
    $token = $_REQUEST['tok'];
    if (!defined('CURL_HTTP_VERSION_2_0')) {
      define('CURL_HTTP_VERSION_2_0', 3);
    }
    // open connection 
    $http2ch = curl_init();
    curl_setopt($http2ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
    // send push
    $apple_cert = 'certificate_name.pem';
    $message = '{"aps":{"action":"message","title":"your_title","body":"your_message_body"}}';
    $http2_server = 'https://api.development.push.apple.com'; // or 'api.push.apple.com' if production
    $app_bundle_id = 'your bundle id';
    $status = sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token);
    echo $status;
    // close connection
    curl_close($http2ch);
    function sendHTTP2Push($http2ch, $http2_server, $apple_cert, $app_bundle_id, $message, $token) 
    {
        // url (endpoint)
        $url = "{$http2_server}/3/device/{$token}";
        $cert = realpath($apple_cert);
        // headers
        $headers = array(
            "apns-topic: {$app_bundle_id}",
            "User-Agent: My Sender"
        );
        curl_setopt_array($http2ch, array(
            CURLOPT_URL => $url,
            CURLOPT_PORT => 443,
            CURLOPT_HTTPHEADER => $headers,
            CURLOPT_POST => TRUE,
            CURLOPT_POSTFIELDS => $message,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSLCERT => $cert,
            CURLOPT_HEADER => 1
        ));
        $result = curl_exec($http2ch);
        if ($result === FALSE) {
          throw new Exception("Curl failed: " .  curl_error($http2ch));
        }
        // get response
        $status = curl_getinfo($http2ch, CURLINFO_HTTP_CODE);
        if($status=="200")
        echo "SENT|NA";
        else
        echo "FAILED|$status";
    }
    ?> 
    
    
    
    感谢您的回复,我试着打印日志,但没有效果。但是在添加本地通知时,我看到它在工作。它解决了吗?是否需要将.voip添加到应用程序包的末尾?另外,当我调用此脚本时,我得到了
    原因:“杀死应用程序,因为它在收到PushKit VoIP推送回调后从未向系统发送传入呼叫。”
    是否有可能我遗漏了什么?是的,您必须添加.VoIP与您的bundle id类似-$app\u bundle\u id='yourbundleid.VoIP';