我如何在voip中接收消息?我可以获得Voip Token!
我在目标c:
中写作我在itnernet中搜索过,但无法找到任何解决方案!所有我发现的都是Swift,但是不能在swift中获得令牌,但是我可以得到令牌,但不能从一行获取消息。
apn push"" -c backgroundfetch.pem -m"你好"
如何在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>
答案 0 :(得分:0)
在您的情况下,解决方案是发送静默推送通知。静默推送通知到达后,使用后台任务执行代码。
以下是发送静默推送通知的良好解释。