-1

How can I receive Messages in voip? I can get the Voip Token!

I'm writing in Objective C:

I have searched around the internet but can't find any solutions! All I found is Swift, but can't get the token in Swift. In Objective C I can get token but not get Messages from a line.

apn push "<Token>" -c backgroundfetch.pem -m "Hello"

How can I popup a Messages in Objective C? Here is my code:

#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

My info.plist:

<key>UIBackgroundModes</key>
<array>
    <string>voip</string>
    <string>audio</string>
    <string>fetch</string>
    <string>remote-notification</string>
</array>
Olivia Stork
  • 4,660
  • 5
  • 27
  • 40
  • Could you explain me the need of implementation of VOIP push in the application? Based on your requirement I can suggest you the best way. –  May 19 '18 at 09:03
  • hello, my need is to trigger an appilcation in my phone. So i will like to 'wake up' the phone and exucute some code statements that i have made. My idea is: i have a token, and send to a specific device, and then run the statements! – Frederik Frandsen May 19 '18 at 09:42
  • Well in this case you can send a silent push notification and on received of notification you can execute code. But remember your app will not open in foreground. it will remain in background only. –  May 19 '18 at 10:39
  • How do I send a "silent push notification"? Which code do I have to use to send a "silent push notification"? – Frederik Frandsen May 19 '18 at 14:15

1 Answers1

0

In your case the solution is to send a silent push notification. Once the silent push notification arrives, execute your code with background task.

Here is the good explanations for sending a silent push notification.

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