【发布时间】:2018-05-18 12:40:21
【问题描述】:
如何在 voip 中接收消息?我可以得到 Voip 令牌!
我正在用 Objective C 编写代码:
我在互联网上搜索过,但找不到任何解决方案!我发现的只是 Swift,但无法在 Swift 中获取令牌。在 Objective C 中,我可以获取令牌,但不能从一行获取消息。
apn push "<Token>" -c backgroundfetch.pem -m "Hello"
如何在 Objective C 中弹出消息?这是我的代码:
#import "AppDelegate.h"
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@import PushKit;
@import UserNotifications;
@interface AppDelegate ()
@end
@implementation AppDelegate
NSString *fcmToken = @"";
// Trigger VoIP registration on launch
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self voipRegistration];
return YES;
}
// Register for VoIP notifications
- (void) voipRegistration {
dispatch_queue_t mainQueue = dispatch_get_main_queue();
// Create a push registry object
PKPushRegistry * voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
// Set the registry's delegate to self
voipRegistry.delegate = self;
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
if([credentials.token length] == 0) {
NSLog(@"voip token NULL");
return;
}
NSLog(@"PushCredentials: %@", credentials.token);
}
// Handle incoming pushes
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
// Process the received push
NSLog(@"Get");
}
@end
我的info.plist:
<key>UIBackgroundModes</key>
<array>
<string>voip</string>
<string>audio</string>
<string>fetch</string>
<string>remote-notification</string>
</array>
【问题讨论】:
-
你能解释一下在应用程序中实现VOIP推送的需要吗?根据您的要求,我可以建议您最好的方法。
-
你好,我需要在我的手机中触发一个应用程序。所以我想“唤醒”电话并执行我所做的一些代码语句。我的想法是:我有一个令牌,然后发送到特定的设备,然后运行语句!
-
那么在这种情况下,您可以发送静默推送通知,并在收到通知后执行代码。但请记住,您的应用程序不会在前台打开。它将仅保留在后台。
-
如何发送“静默推送通知”?我必须使用哪个代码来发送“静默推送通知”?
标签: objective-c firebase-cloud-messaging token message voip