【问题标题】:How can i receive Messages in voip?如何在 voip 中接收消息?
【发布时间】: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


【解决方案1】:

在您的情况下,解决方案是发送静默推送通知。静默推送通知到达后,使用后台任务执行您的代码。

这里是发送静默推送通知的很好解释。

https://stackoverflow.com/a/36327058/9106403

【讨论】:

  • Hej 感谢您的链接,但“内容可用”不会唤醒 iPhone(当实际应用处于非活动状态时。不在后台模式下),并进入后台模式。
  • 所以你想看到推送?
  • 我想启动一个非活动的应用程序。
  • 意味着您希望您的应用程序在后台启动,并且静默推送通知是最好的选择。它不会通知推送接收的用户,您可以在后台执行您的代码。
  • 我的意思是处于非活动模式并启动应用程序并执行代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多