2
votes

Does anyone know why the following method within my app would receive a null deviceToken after registering with APNS (with MonoTouch)?

public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken){ // }

Thanks.

1

1 Answers

4
votes

The debugger says that the deviceToken is null but it is not. (At least that is what I observe) You can use the code below to build a string that represents your device token.

public override void RegisteredForRemoteNotifications (UIApplication application, NSData deviceToken)
{
    byte [] token = deviceToken.ToArray ();
    string tokenString = "";

    for (int i=0; i<deviceToken.Length; i++)
        tokenString += token[i].ToString ("X2");

    Console.WriteLine (tokenString);
}

Here is a good tutorial that explains push notifications. It is for XCode but it is easy to convert.