wei-spring / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

push device id after registering for push is coming as null #789

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please clearly state whether the issue relates to a device/the simulator or
the tools.
This happens in real device.
If related to a device be sure to specify exactly which device with as much
details as possible.

On iPhone 4, latest OS version and also on Android phones.

What steps will reproduce the problem?
1. Have a device register for push using following code:
            Hashtable meta = new Hashtable(1);
            meta.put(com.codename1.push.Push.GOOGLE_PUSH_KEY, "359276012902");
            Display.getInstance().registerPush(meta, false);
2. The PushCallback registeredForPush(String deviceId) is called by cn1 
framework.
3. The deviceId received in the registeredForPush() for iPhone 4 device is 
given below:

b018aa2534e7abf5da59f9c673e255eb107cf3f771022db31d3a215c8e8f4c8b

4. after this when you try to get the cn1 specific device id, it is coming as 
null from the following call:
com.codename1.push.Push.getDeviceKey();

What is the expected output? What do you see instead?

the cn1 specific device id which is a long value should be available so that 
push to specific device can be made.

What version of the product are you using? On what operating system?

Latest cn1 version on build server and latest plugin.

Please provide any additional information below.

Original issue reported on code.google.com by nir...@nvsoft.com on 20 Jul 2013 at 5:13

GoogleCodeExporter commented 9 years ago
And the deviceId received in the registeredForPush() method call for the 
Android device is given below:

APA91bEGGy-IEO0JXGGRwzLnHgngKHacbwm3-quT-EUXVTqDfa7f3SrArH3Xv7ev3cxURCXAPgA70Pdg
Gh75DawxZRDowtkNdISaDmJTQ1EyfLIS0RwYiRKXXjNPIvr__bGRgU9bAiZuVuIS9KnpEh86l0P4Cr92
7A

Original comment by nir...@nvsoft.com on 20 Jul 2013 at 5:22

GoogleCodeExporter commented 9 years ago

Original comment by shai.almog on 20 Jul 2013 at 5:29

GoogleCodeExporter commented 9 years ago
Looking at the code, is it possible that this only happens to you the first 
time around and after that it works?
There is a delay between receiving the native push ID and the actual final push 
registration in the server. This is probably something we need to fix.
Anyway, I'll update the server within the next couple of hours with some 
logging, if you could then reproduce the problem and attach the DDMS logs that 
could be helpful in pinpointing the source of the issue.

Original comment by shai.almog on 21 Jul 2013 at 7:55

GoogleCodeExporter commented 9 years ago
FYI I updated the server and included a fix for the callback being 
asynchronous. I also made an additional improvement to the backend server.

Original comment by shai.almog on 21 Jul 2013 at 9:46

GoogleCodeExporter commented 9 years ago
I added some more logs to my app and it seems the cn1 push id is null initially 
when my app receives the registeredForPush callback. However afterwords it is 
getting some value. I got a value of 14196178 for the iphone 4 device above.

However when I try to use this id and call the server side method to push the 
notification to this device, it seems to be hanging and the thread on which 
this is called, just don't return. This method is used for pushing the msg:

Push.sendPushMessage(notificationMsg, cn1PushDeviceId, isProdEnv, 
googleServerKey, iosPushCertURL, iosPushCertPassword);

Original comment by nir...@nvsoft.com on 21 Jul 2013 at 7:02

GoogleCodeExporter commented 9 years ago
If you sent a build in the past 9 hours the problem of asynchronicity should be 
fixed. The callback should arrive after we have server response from the cloud.

Send push is a blocking method, is it possible there are other network 
operations preventing it from running? Are you invoking it from another network 
operation?

Original comment by shai.almog on 21 Jul 2013 at 7:24

GoogleCodeExporter commented 9 years ago
I have been building my app against the server cn1 version 1.1. Do I need to 
build against latest version to get this fix?

Original comment by nir...@nvsoft.com on 22 Jul 2013 at 4:58

GoogleCodeExporter commented 9 years ago
We can't fix the 1.1 version otherwise we would be bound to add regressions. We 
don't change the 1.1 version at all in the servers to avoid such cases.

Original comment by shai.almog on 22 Jul 2013 at 5:02

GoogleCodeExporter commented 9 years ago
ok, I will try with the latest version. There is one more question I had 
regarding push to android device:

In the KitchenSink demo, the code uses the following code to send push msg to a 
device:

com.codename1.push.Push.sendPushMessage("Hi Kitchen Sink users!", devKey, 
false, GOOGLE_SERVER_KEY, IOS_CERTIFICATE_URL, IOS_CERTIFICATE_PASSWORD);

However the documentation on Push class, mentions GOOGLE_AUTH_KEY 
(googleAuthKey - authorization key from the google play store) as the argument 
to be passed to sendPushMessage method call. Can you please confirm which key 
we are suppose to use here?

Original comment by nir...@nvsoft.com on 22 Jul 2013 at 5:15

GoogleCodeExporter commented 9 years ago
The docs are in error. This needs to be the keys from the cloud API console.

Original comment by shai.almog on 22 Jul 2013 at 5:20

GoogleCodeExporter commented 9 years ago
I tested with the latest code on iPhone. Now, the cn1 push device id is not 
coming as null. However another problem is that the iphone app is not 
registered for push notification. Earlier build would cause the apple iOS to 
ask for user permission to enable notification and the app would also show up 
on the notifications list in the settings of the iphone. However with latest 
version is not asking for the push registration permission and the app is also 
not showing up in the notifications center. However the registeredForPush 
callback is getting called and the following device ids are getting being shown:

Native device id: 
b018aa2534e7abf5da59f9c673e255eb107cf3f771022db31d3a215c8e8f4c8b

 cn1PushDeviceId: 13815159

Can you please advice what is the issue here?

Original comment by nir...@nvsoft.com on 22 Jul 2013 at 6:56

GoogleCodeExporter commented 9 years ago
Did you define ios.includePush=true in the build args?
When sending a build with sources included if you open IOSNative.m do you see 
the line #define INCLUDE_CN1_PUSH2 defined there or is it missing?

Original comment by shai.almog on 22 Jul 2013 at 8:39

GoogleCodeExporter commented 9 years ago
Yes, the ios.includePush=true in the build args.
And IOSNative.m has the following line:

#define INCLUDE_CN1_PUSH2

Original comment by nir...@nvsoft.com on 22 Jul 2013 at 9:47

GoogleCodeExporter commented 9 years ago
Make sure you are using a proper mobile provisioning file that doesn't use * in 
the package name. I'm assuming you are using the development not production 
build right?
Open your ipa using a zip application then find the file 
embedded.mobileprovision, open it in the text editor where you should see a 
section like this:
    <key>Entitlements</key>
    <dict>
        <key>application-identifier</key>
        <string>Q5GHSKAL2F.com.codename1.demos.kitchen</string>
        <key>aps-environment</key>
        <string>development</string>
        <key>get-task-allow</key>
        <true/>

Can you verify that the values there make sense (you will see a lot of other 
giberish around) and ideally post it here too?

Original comment by shai.almog on 22 Jul 2013 at 10:40

GoogleCodeExporter commented 9 years ago
I am using the "Send iOS AppStore build" target in netbeans for building. 
However since this build is used for testing currently, during sendPushMessage 
- I am passing production as false.
My provisioning profile is correct, and package name does not contains a "*" in 
the end. Actually I am using the same provisioning profile to build against 
version 1.1 and it works(in the sense app is added in the notification center). 
However for the latest version build, it is not added. 

I have pasted the values from my embedded.mobileprovision file from the ipa 
built using the latest version:

    <key>Entitlements</key>
    <dict>
        <key>application-identifier</key>
        <string>KF4G994665.com.nvsoft.s2pay</string>
        <key>aps-environment</key>
        <string>production</string>
        <key>com.apple.developer.default-data-protection</key>
        <string>NSFileProtectionComplete</string>
        <key>get-task-allow</key>
        <false/>
        <key>keychain-access-groups</key>
        <array>
            <string>KF4G994665.*</string>
        </array>
    </dict>
    <key>ExpirationDate</key>
    <date>2014-04-09T07:34:50Z</date>

However the app installed using this ipa file, does not go into the 
notification center.

Original comment by nir...@nvsoft.com on 22 Jul 2013 at 10:52

GoogleCodeExporter commented 9 years ago
This won't work for you, as you can see your build is marked as production 
still. You can only do sandbox pushes during development. If you switch to a 
development build will it appear in the notification center?
I'm not sure how it works for you with 1.1 since the main thing we change there 
is the libraries.

Original comment by shai.almog on 22 Jul 2013 at 11:05

GoogleCodeExporter commented 9 years ago
I also did a build with development target and latest version and here are the 
Entitlements from it:

    <key>Entitlements</key>
    <dict>
        <key>application-identifier</key>
        <string>KF4G994665.com.nvsoft.s2pay</string>
        <key>aps-environment</key>
        <string>development</string>
        <key>com.apple.developer.default-data-protection</key>
        <string>NSFileProtectionComplete</string>
        <key>get-task-allow</key>
        <true/>
        <key>keychain-access-groups</key>
        <array>
            <string>KF4G994665.*</string>
        </array>
    </dict>
    <key>ExpirationDate</key>
    <date>2014-04-10T07:26:20Z</date>

It is also not showing in the push notification center.

Original comment by nir...@nvsoft.com on 23 Jul 2013 at 9:50

GoogleCodeExporter commented 9 years ago
Are you getting a pushRegistrationError() call?
I looked at the push registration code and can't see anything that's different 
and as far as I can tell its not the code that should put you in the 
notification center. However, I did notice the code is executed on our thread 
instead of Apples thread so I am in the process of moving the code to Apples 
thread which I hope would resolve the issue (because I'm seriously fresh out of 
guesses). 
I'll update the issue once I've uploaded this change to the server.

Original comment by shai.almog on 23 Jul 2013 at 10:44

GoogleCodeExporter commented 9 years ago
No I am not getting the pushRegistrationError() call. It is calling 
registeredForPush() call.

Thanks Shai, I have been trying to get push to work but somehow not been 
successful and getting it work, would help a lot.

Original comment by nir...@nvsoft.com on 23 Jul 2013 at 11:42

GoogleCodeExporter commented 9 years ago
I've updated the server, hopefully this will fix the issue.

Original comment by shai.almog on 23 Jul 2013 at 12:13

GoogleCodeExporter commented 9 years ago
Hi Shai,

I tried with the latest code. Now the app is showing in the notification 
center. 

However when I tried to send push message to it (in the development version), 
the app is not getting the message. The boolean result from the following call 
is coming as "true" but message is not received:

com.codename1.push.Push.sendPushMessage("Hi Kitchen Sink users!", devKey, 
false, GOOGLE_SERVER_KEY, IOS_CERTIFICATE_URL, IOS_CERTIFICATE_PASSWORD);

Original comment by nir...@nvsoft.com on 23 Jul 2013 at 1:51

GoogleCodeExporter commented 9 years ago
FYI, the latest code which I tried has the following cn1 push id: 13859734.

Original comment by nir...@nvsoft.com on 23 Jul 2013 at 1:53

GoogleCodeExporter commented 9 years ago
Let me do a little dance for resolving the first issue ;-) Tough one!
I think I see the second issue, it seems like a memcache issue on the server 
and you should have gotten the message now. I'm working on fixing it.

Original comment by shai.almog on 23 Jul 2013 at 6:51

GoogleCodeExporter commented 9 years ago
OK. Workaround for that issue should be up too.

Original comment by shai.almog on 23 Jul 2013 at 6:57

GoogleCodeExporter commented 9 years ago
Tried with latest build, but Sorry, still haven't received the push messages.

The latest native id and cn1 push id are shown here:

native id: 3a31e625a8b3437625957d6a15f7bbfc4e88a6991cfeb29f9c0d1383b908d889

cn1PushId: 13859734

The result from sendPushMessage, still shows "true" but no message on the 
client app.

Anything else can be checked?

Original comment by nir...@nvsoft.com on 24 Jul 2013 at 5:55

GoogleCodeExporter commented 9 years ago
Push.sendPushMessage() call works from mobile app. However when I try to call 
the same using JavaSEPort in my Web application, it is failing.  Actually, when 
it is trying to get the following property:

Display.getInstance().getProperty("built_by_user", "");

It is waiting for the user input at the following line:
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:503)
        at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:247)
        - locked <0x0000000784c9b2c0> (a java.awt.Component$AWTTreeLock)
        at java.awt.Dialog.show(Dialog.java:1072)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:870)
        at javax.swing.JOptionPane.showConfirmDialog(JOptionPane.java:796)
        at javax.swing.JOptionPane.showConfirmDialog(JOptionPane.java:758)
        at com.codename1.impl.javase.JavaSEPort.getProperty(JavaSEPort.java:3415)
        at com.codename1.ui.Display.getProperty(Display.java:2363)

How to avoid this? As I am running in a web app and JavaFx is not there nor 
user can input anything.

Original comment by nir...@nvsoft.com on 24 Jul 2013 at 12:06

GoogleCodeExporter commented 9 years ago
Just use Display.getInstance().setProperty("built_by_user", emailOfProUser);

Original comment by shai.almog on 24 Jul 2013 at 5:44

GoogleCodeExporter commented 9 years ago
ok, with setProperty, now the server is also able to make the sendPushMessage() 
call. 

However, still no push message is received on the mobile device. Does it show 
any error on the server side? 

Original comment by nir...@nvsoft.com on 25 Jul 2013 at 1:44

GoogleCodeExporter commented 9 years ago
Which mobile? I thought you were able to push from the device?
Is it not working to Android or to iOS?
Which device id's?

Original comment by shai.almog on 25 Jul 2013 at 6:39

GoogleCodeExporter commented 9 years ago
From iPhone IOS the same device I'd and cn1 push device Id that I mention 
earlier. The sendPushMessage call returns true(when called from device or from 
server), but the mobile device is not able to get any of the push messages.

Original comment by nir...@nvsoft.com on 25 Jul 2013 at 10:36

GoogleCodeExporter commented 9 years ago
Thanks Shai,

Now the push messages are coming to the iPhone device. Will test android and  
let you know.

Original comment by nir...@nvsoft.com on 26 Jul 2013 at 2:57

GoogleCodeExporter commented 9 years ago
Push on android device is also working now. Thanks

Original comment by nir...@nvsoft.com on 26 Jul 2013 at 2:09

GoogleCodeExporter commented 9 years ago
Further update, actually my app's push() method of the PushCallback does not 
seem to be called when the app is running. I am now seeing the push messages 
(in iPhone) when the app is not running or it is in the background. But when 
the app is in the foreground the push messages are not being received or 
probably method on my callback is not getting called. How should I debug this?

Original comment by nir...@nvsoft.com on 27 Jul 2013 at 2:54

GoogleCodeExporter commented 9 years ago
Interesting. Did you implement the PushCallback interface on the main class?
Is this only on iOS or on Android too?

Original comment by shai.almog on 27 Jul 2013 at 6:56

GoogleCodeExporter commented 9 years ago
I have implemented the PushCallback on main app class as well as statemachine. 
From main app class I am calling the method in statemachine class.

I will test the behavior on android tomorrow.

Original comment by nir...@nvsoft.com on 28 Jul 2013 at 4:31

GoogleCodeExporter commented 9 years ago
I tested the behaviour on android phone and it is also not getting the push 
message if the application is in the foreground.

I put debug statements on my main application class which implements the 
PushCallback, but even those debug stmts are not coming when the app is in the 
foreground.

Can you please help?

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 12:23

GoogleCodeExporter commented 9 years ago
When I tried to debug the application on iphone, I put a breakpoint on the 
following method(objC):

com_codename1_impl_ios_IOSImplementation_pushReceived

However, when the app is in the foreground - this method is not getting called 
when push message is sent to the device.

Can you please provide some guidance as to which method should be called so 
that I can put a breakpoint on that method.

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 12:49

GoogleCodeExporter commented 9 years ago
Check out CodenameOne_GLAppDelegate.m: didReceiveRemoteNotification

From your previous posts I understood that this did work? What changed?
Did it only work when the app was in the background?

Original comment by shai.almog on 29 Jul 2013 at 1:33

GoogleCodeExporter commented 9 years ago
Yes, the push notification works only when app is in the background.

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 2:12

GoogleCodeExporter commented 9 years ago
If it were only on iOS or only on Android I'd assume its a bug in the platform 
but since it doesn't work for neither I'm assuming something went wrong 
elsewhere. How are you sending the push? 

Original comment by shai.almog on 29 Jul 2013 at 3:16

GoogleCodeExporter commented 9 years ago
I am sending the push using the server side code:
Push.sendPushMessge() 

The same server side code to push msg works when the app is in the background 
or not running. 

However when the app is running in foreground it does not get the push msg.

I believe it might be some issue on the client side. However the behavior is 
the same in android and iOS. Hence I am not sure how to debug?

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 4:12

GoogleCodeExporter commented 9 years ago
Is it working for you if you send a push from the simulator/device?
Is it possible you have an old version of the JavaSE jar?

Original comment by shai.almog on 29 Jul 2013 at 4:32

GoogleCodeExporter commented 9 years ago
I have not tried push from the device/simulator. I will try that.

From server side the push seems to be going and received at the client when app 
is not in foreground. So I think the push must be going from server but some 
logic on client is causing it to not show when app is running in foreground. Do 
you think, logic on server will make difference in this situation? My 
javase.jar will be about 3 to 4 days old then the latest jar.

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 5:01

GoogleCodeExporter commented 9 years ago
Not if its 4 days old. An older version might have had a different default 
"type" attribute that might have hidden the value received but the newer 
version should be the same for the most part. Did you place a breakpoint in the 
method I mentioned in the objective C code? Does it get invoked?

Original comment by shai.almog on 29 Jul 2013 at 5:38

GoogleCodeExporter commented 9 years ago
On putting the breakpoint on CodenameOne_GLAppDelegate.m: 
didReceiveRemoteNotification:

This method is getting invoked when msg is pushed to the device. However the it 
does not enter any of the two if blocks in the method. I have attached the 
screenshot which shows the object value of the userInfo.

Can you see any issue there?

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 6:05

Attachments:

GoogleCodeExporter commented 9 years ago
And for your information, the JavaSE.jar in my server is having files which are 
having date of Jul 10.

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 6:23

GoogleCodeExporter commented 9 years ago
Can you move this log:
        NSLog(@"Received notification: %@", userInfo);
So it will print out and get the printout from the console so I can see the 
message contents you are receiving?
Thanks.

Original comment by shai.almog on 29 Jul 2013 at 7:21

GoogleCodeExporter commented 9 years ago
Here's the output after moving the log:

2013-07-30 03:25:36.000 S2PayApp[3613:907] Received notification: {
    aps =     {
        alert = "{\"ID\":\"1520041\",\"CB\":\"oYtZYpdRuGty9dZKz9IY8hS0GcgRiwU91m6qTOgrieHDXYzF67rZb6Ytj8V+jo+kZ4jA06DudGZAKANvZVi7sQ==\",\"TYPE\":\"NCN\"}";
    };
}

Original comment by nir...@nvsoft.com on 29 Jul 2013 at 9:57

GoogleCodeExporter commented 9 years ago
This might be a client side issue after all. Can you change:
    if( [apsInfo objectForKey:@"alert"] != NULL)

To:
    if( [[userInfo valueForKey:@"aps"] valueForKey:@"meta"] != NULL)

And see is this solves the issue on iOS?

Original comment by shai.almog on 30 Jul 2013 at 4:50

GoogleCodeExporter commented 9 years ago
When I changed:
   if( [apsInfo objectForKey:@"alert"] != NULL)
TO:
   if( [apsInfo objectForKey:@"aps"] != NULL)

It started working.

The next if block is using the following check:
if( [userInfo objectForKey:@"meta"] != NULL)

Do you mean to change that? As there is no "meta" key in the UserInfo received 
by client.

Original comment by nir...@nvsoft.com on 30 Jul 2013 at 5:12