1

I have registered with Urban Airship, obtained the app key, secret and master secret. I have integrated their library as well.

-(void)setupUrbanAirship
{
    UAConfig *config = [UAConfig defaultConfig];
    config.detectProvisioningMode = YES;
    config.productionLogLevel=NO;
    config.inProduction = NO;
    config.developmentAppKey = @"XXXXXXXXXXXXXXXXXXX";
    config.developmentAppSecret = @"XXXXXXXXXXXXXXXXX";

    [UAirship takeOff:config];

    [UAirship push].userPushNotificationsEnabled = YES;

    [UAirship push].userNotificationTypes = (UIUserNotificationTypeAlert |
                                             UIUserNotificationTypeBadge |
                                             UIUserNotificationTypeSound);
}

I am calling this in my code:

NSString *channelID = [UAirship push].channelID;
NSLog(@"channelID %@",channelID);

During the first run of the app the channelID is always null.

I am able to receive the channelID during the second run but not during the first run. Could anyway suggest a way for the app to obtain the channelID during the first run itself. Thanks in advance.

Edited:

According to ralepinski's suggestion I am adding the '[UAirship push].registrationDelegate = self.registrationDelegate' line of code.

In ViewController.h :

@interface ViewController : UIViewController
{
    IBOutlet UIButton *selectButton;
    NSTimer *channelIDDetectionTimer;
}
@property (nonatomic, weak, nullable) id<UARegistrationDelegate> registrationDelegate;

In ViewController.m I am also using these lines of code:

-(void)initRegistration
{
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

    NSString *channelID = [UAirship push].channelID;
    NSLog(@"channelID %@",channelID);
    if (channelID!=nil)
    {
        [delegate saveChannelID];
        if (channelIDDetectionTimer!=nil)
        {
            [channelIDDetectionTimer invalidate];
            channelIDDetectionTimer = nil;
        }
    }
    else
    {
        [UAirship push].registrationDelegate = self.registrationDelegate;
        //[[UAPush alloc]updateRegistration];
            // Registering for only UIRemoteNotificationTypeNone will not result in a
            // device token registration call. Instead update chanel registration directly.
    }
}

-(void)viewWillAppear:(BOOL)animated
{
    channelIDDetectionTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(initRegistration) userInfo:nil repeats:YES];
}

I have enabled remote-notifications in the capabilities section of the app target. Still I get the ChannelID as null during the app's first run. Let me know. Thanks.

Nitin
  • 63
  • 7

2 Answers2

2

The channel creation relies on a network request. It wont immediately be available, but you can listen for when its available using UARegistrationDelegate. You can assign the delegate on the UAPush instance here:

[UAirship push].registrationDelegate = self.registrationDelegate;

Sometimes the channel registration is delayed to the next app foreground if the SDK is unable to generate a deviceToken. If you enable remote-notifications in the capabilities section of your application the device token will be generated immediately, and the channel created during the first run.

ralepinski
  • 1,756
  • 8
  • 15
  • 1
    Hi ralepinski, I have enabled remote-notifications in the capabilities section of the app target. Yet the channel Id doesn't get created during the first run. What could be the issue ? – Nitin Oct 16 '15 at 07:57
  • 2
    It works now. The 'setupUrbanAirship' method was called much later hence the error. By placing it in the application-did-finish-launching delegate method and by adding your code the channel ID was assigned almost immediately. – Nitin Oct 18 '15 at 14:36
  • 1
    Glad you figured it out! – ralepinski Oct 19 '15 at 17:40
0

In my case the ChannelCreated event was triggered up to 3 mins after the first lunch.. Just had to be very patient..

Maybe an API issue with Apple or Airship ?

(I'm using Airship with Expo and React-Native)

  Airship.addListener(
    EventType.ChannelCreated,
    async ({ channelId }) => {
      console.log(" Airship - ChannelCreated", channelId);
    }
  );
Made in Moon
  • 2,294
  • 17
  • 21