ios设备中未收到VoIP推送[关闭]
Posted
技术标签:
【中文标题】ios设备中未收到VoIP推送[关闭]【英文标题】:Voip push not received in ios device [closed] 【发布时间】:2017-02-02 13:56:36 【问题描述】:我想为我的应用程序添加 voip 推送支持。我按照link 中的步骤操作。在从休斯顿发送推送时,它显示“1 个推送通知发送成功”。我使用 amazon sns 进行了相同的尝试,它说推送已成功发布,但我没有看到在注册表委托处收到推送,即 didReceiveIncomingPushWithPayload。我尝试使用 voip 分发配置文件进行此操作。 任何帮助将不胜感激。
【问题讨论】:
解决了吗? 【参考方案1】:可能的原因:
-
您的 .pem 证书可能有误。
您的 BundleId 可能有误。
您的设备 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 添加到应用程序包的末尾?另外,当我调用此脚本时,我收到reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'
是否有我遗漏的东西?
是的,您必须添加带有捆绑 ID 的 .voip - 像 - $app_bundle_id = 'yourbundleid.voip' ;【参考方案2】:
Here是跟随VOIP步骤的一个链接。
当您收到任何 voip 通知时,然后 didReceiveIncomingPushWithPayload 得到调用。您可以从那里通过本地通知通知用户。
【讨论】:
感谢您的回复,我尝试打印日志,但没有成功。但是在添加本地通知时,我发现它起作用了。【参考方案3】:参考 https://github.com/hasyapanchasara/PushKit_SilentPushNotification
Objective 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:.
【讨论】:
以上是关于ios设备中未收到VoIP推送[关闭]的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Node JS 中使用 Amazon SNS 向 iOS 设备发送 VoIP 推送通知
在 iOS8.0.2 上没有收到 Pushkit voip 推送通知