Get device token for push notification (iOS)

Get device token for push notification (iOS)

{$a->নাম} - {$a->তারিখ} দ্বারা
Number of replies: 3

I am trying to get the push notification token for my device in the mobile app for testing, but it is not being returned. How do you handle this?

What I do is to modify the AppDelegate of the generated application. Do you have any idea?

didRegisterForRemoteNotificationsWithDeviceToken is not executed, the code is as follows:


#import "AppDelegate.h"

#import "MainViewController.h"

#import <UserNotifications/UserNotifications.h>


@interface AppDelegate () <UNUserNotificationCenterDelegate>

@end


@implementation AppDelegate


- (BOOL)applicationদুঃখিতUIApplication*)application didFinishLaunchingWithOptionsদুঃখিতNSDictionary*)launchOptions

{

    self.viewController = [[MainViewController alloc] init];

    [self enableNotifications];

    UNUserNotificationCenter.currentNotificationCenter.delegate = self;


    return [super application:application didFinishLaunchingWithOptions:launchOptions];

}


- (void) enableNotifications{

    UNAuthorizationOptions options = UNAuthorizationOptionAlert + UNAuthorizationOptionSound;

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

    

    [center requestAuthorizationWithOptions:options

     completionHandler:^(BOOL granted, NSError * _Nullable error) {

      if (!granted) {

        NSLog(@"Something went wrong");

      }

      else{

        dispatch_async(dispatch_get_main_queue(), ^{

            [[UIApplication sharedApplication] registerForRemoteNotifications];

        });

      }

    }];

}


- (void)applicationদুঃখিতUIApplication *)application didRegisterForRemoteNotificationsWithDeviceTokenদুঃখিতNSData *)deviceToken{

    // -- get token here....

}


- (void)applicationদুঃখিতUIApplication *)application didFailToRegisterForRemoteNotificationsWithErrorদুঃখিতNSError *)error{

    NSLog(@"Error");

}


@end



রেটিং এর গড়: -
In reply to Charlie Villa

Re: Get device token for push notification (iOS)

{$a->নাম} - {$a->তারিখ} দ্বারা
Core developers এর ছবি Moodle HQ এর ছবি Particularly helpful Moodlers এর ছবি Peer reviewers এর ছবি Plugin developers এর ছবি
Hi,

we store the token to send the push notifications in here:


You can also view it by running the app and going to App Settings > About > Device info > Push notifications ID

If you need to get it dynamically in iOS native code then I don't know how it's done, most of our development is in typescript.

Cheers,
Dani
In reply to Dani Palou

Re: Get device token for push notification (iOS)

{$a->নাম} - {$a->তারিখ} দ্বারা
Hi I was able to locate where you can get the push token for iOS... but you have to make some modifications to the code. The application makes use of a plugin called "phonegap/phonegap-phonegap-plugin-push", this plugin is currently deprecated.

For this reason, the mobile application is not correctly generating this push token for devices with iOS 13 or later.

If you want to make it work, you have to go to the plugin code, specifically to the PushPlugin.m file and make the corresponding modifications to the Objective-C method:
- (void)didRegisterForRemoteNotificationsWithDeviceTokenদুঃখিতNSData *)deviceToken