-1

I am Go through with the WWDC CallKit session and I am comfortable with the Concept of it, But don't know how to start.

Also, I have Following the Sample Code for the CallKit by Apple Developers i.e SpeakerBox. But this one is in Swift.

Need suggestion!!

Thanks in Advance

MayankSengar
  • 284
  • 5
  • 19
  • Please have a look on it. https://medium.com/@abhishekthaplithapliyal/ios-10-callkit-in-objective-c-17eae5174cb8 – aBilal17 Mar 28 '18 at 10:34
  • 1
    Here is code in Objective c. https://github.com/naandonov-mm/iOS-10-Sampler/tree/master/CallKit – aBilal17 Mar 28 '18 at 10:38
  • Yes, I accept your answer, But please do more specify it, your way of explaining the answer decreases the question importance. Flags Dereases. – MayankSengar Mar 28 '18 at 10:57

1 Answers1

7

Here you go. There is a full example in Objective c.

For reference: https://github.com/naandonov-mm/iOS-10-Sampler/tree/master/CallKit

The CallKit framework provides programmatic access to VoIP functionality, as well as call blocking and identification. Note: This sample requires a device to be built on.

To Start first add the following code in App delegate.

 #import <Intents/Intents.h>
 #import <PushKit/PushKit.h>
 @interface AppDelegate () <PKPushRegistryDelegate>

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     // Override point for customization after application launch.
     PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
     pushRegistry.delegate = self;
     pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];

    return YES;
}

Then add following methods in app delegate as well.

 - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray * _Nullable))restorationHandler {
    if ([userActivity.interaction.intent isKindOfClass:[INStartAudioCallIntent class]]) {
        INPerson *person = [[(INStartAudioCallIntent*)userActivity.interaction.intent contacts] firstObject];
        NSString *phoneNumber = person.personHandle.value;
        CallViewController *viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"CallViewController"];
        viewController.phoneNumber = phoneNumber;
        UIViewController *mainViewController = self.window.rootViewController;
        [mainViewController presentViewController:viewController animated:YES completion:nil];
    }
    return YES;
}

#pragma mark - PKPushRegistryDelegate

 - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
    if([credentials.token length] == 0) {
        NSLog(@"voip token NULL");
        return;
    }
}

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
    NSString *uuidString = payload.dictionaryPayload[@"UUID"];
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];
    NSString *phoneNumber = payload.dictionaryPayload[@"PhoneNumber"];
    CallViewController *viewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil]instantiateViewControllerWithIdentifier:@"CallViewController"];
    viewController.phoneNumber = phoneNumber;
    viewController.isIncoming = YES;
    viewController.uuid = uuid;
    UIViewController *mainViewController = 
    self.window.rootViewController;
    [mainViewController presentViewController:viewController animated:YES completion:nil];
}

enter image description here

aBilal17
  • 2,974
  • 2
  • 17
  • 23
  • hello my hero, i have a CallScreen that contain rtc function (only start here), when phone locked i using callkit to show CallScreen, when user accept call i present CallScreen from windowRootView, so i want to ask: when screen locked, user swipe to accept call but not click button to open CallScreen, so how to start rtc? Thanks – famfamfam Sep 24 '20 at 08:39