Passbook not requesting latest version after push - ios

I have implemented the Passbook websevice, and can successfully push to APNs; But I have a problem with the Passbook not requesting the latest version of the pass.
When I push a new notification to a given device, the device gets it and Passbook sends a request the my web service asking for the serial numbers associated with that device. My web service send a response with 200 http status code, whith a JSON payload similar to:
{"lastUpdated":"1424691339", "serialNumbers":["1234567"]}
The device console shows the following:
Feb 23 11:34:54 My-iPhone passd[162] <Warning>: Generating GET request with URL <http://192.168.1.138:8000/api/v1/devices/297f6e6ed478540ccc05e1962cce41e6/registrations/pass.com.example.coupon?passesUpdatedSince=1424690611>
Feb 23 11:34:55 My-iPhone passd[162] <Warning>: Get serial #s task (for device 297f6e6ed478540ccc05e1962cce41e6, pass type pass.com.example.coupon, last updated 1424690611; with web service url http://192.168.1.138:8000/api/) got response with code 200
Feb 23 11:34:55 My-iPhone passd[162] <Warning>: Get serial numbers task completed with update tag 1424691339, serial numbers (
1234567
)
I can't see why Passbook does not proceed and request the latest version of the pass. Instead it stops at that point!
Can someone Help please?

Solved! The Apple docs say that it is required that the serialNumbers entry in the JSON payload must be an array of Strings. This is not enough to make it work. The serial numbers strings must also be quoted for the device to consider them valid. Unfortunately the dumped messages in the device console are of no help to figure this out nor does the documentation. I presume that PassKit converts the string that look like an Integer to NSNumber, when passing the JSON payload, Instead of NSString.
May be if I had other characters than only numbers, this problem wouldn't have occurred.
This is an example of how the JSON payload must look when serial numbers are numbers, duh!
{"lastUpdated":"1424691339", "serialNumbers":["'1234567'"]}

Related

Getting Invalid hex character error while sending Apple push notification via Mobile First Platform

I am trying to send Apple push notification via Mobile First Server. I did that setup three months back and things were working fine. I start facing problem 4-5 days back that states java.lang.RuntimeException: Invalid hex character: y
whenever I try to invoke push notification.
The server logs are as given below.
000004ed com.ibm.pushworks.server.notification.Mediator E FPWSE1081E: Failed sending notification. Please refer to the server log file for more details.
java.lang.RuntimeException: Invalid hex character: y
at com.notnoop.apns.internal.Utilities.charval(Utilities.java:132)
at com.notnoop.apns.internal.Utilities.decodeHex(Utilities.java:119)
at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:85)
at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
at com.ibm.pushworks.server.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:141)
at com.ibm.pushworks.server.notification.apns.APNSMediator.sendNotification(APNSMediator.java:106)
at com.ibm.pushworks.server.notification.Mediator$2.run(Mediator.java:89)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:483)
at java.util.concurrent.FutureTask.run(FutureTask.java:274)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1157)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:627)
at java.lang.Thread.run(Thread.java:809)
Please suggest something to remove this error.
This issue can happen if the token you are using contains invalid hex characters.
Check whether you passing valid APNS token.
Use the following REST API :
http://www.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.apiref.doc/apiref/r_restapi_push_device_registration_get.html
to check the APNS token for your subscription. If the APNS token is proper, verify if you can send a push notification using REST APIs.
We had the same problem with version 7.0. For some reason there was an invalid token in the PUSH_DEVICES table with the following string "32bytes"
We removed that register and the registers related in the PUSH_NOTIFICATIONS table and everything worked fine after that.

Mandrill api log says message is sent, but I don't receive it, and it doesn't show in activity

Using a production key on Mandrill I am attempting to send an email. Previously this has worked without issue. However now, despite receiving a successful response from the API, visible in the api log, no email is being sent, and nothing is present in the outbound activity log.
If I check the api log for the message which appeared to fail it displays:
[
{
"email": [email_address],
"status": "sent",
"_id": [id],
"reject_reason": null
}
]
Replacing the id in the content view of a sent email, with the id from a failed one displays a correctly formatted email:
e.g. https://mandrillapp.com/activity/content?id=20151214_[put_the_id_here]
Is this a bug? What is causing it? Where can I see more information about what happened? How can I monitor if this happens again in the future? How can I prevent it from happening in the future?
I have been in contact with Mandrill support regarding the issue, which they described as 'very strange indeed'. Deleting the API key and generating a new one fixed the issue, but there is no explanation as to why this is they case, how to detect the problem, or how to stop it from happening again in the future.
The messages in question were never actually sent by Mandrill, and displayed no SMTP events, despite reporting as sent by their API
Something else to check is to make sure you're using a working API key instead of a test one. As the name suggests, test keys are designed to work just like a regular key, so the feedback to your program will be identical, but the messages won't actually be sent.
You can see if this is the problem by going to the Mandrill settings and looking at the list of API keys. Test keys have a very clear This is a test key message listed.
This probably won't be an issue if you generated the key yourself, but if you inherited this project it's worth taking a look.
I have faced a similar issue like this last week. The "sent" status only indicates that Mandrill sent it. But reception of the email message is confirmed only if there is a SMTP event corresponding to it with code starting with 2, (example 250 etc), in the info api response, like the following:
"smtp_events": [
{
"ts": 1442448422,
"type": "sent",
"diag": "250 SmtpThread-4622542-14682902148#ps-they-19.uk.miplecast.lan Received OK",
"source_ip": "505.207.171.171",
"destination_ip": "705.139.255.221",
"size": 29501
}
check this link for more info.
https://mandrill.zendesk.com/hc/en-us/articles/205582697-How-to-Confirm-If-an-Email-Was-Actually-Delivered
the issue could be on the recipient server as well, due which delivery could be delayed. In our experience last week, the message was delivered 4 hours after being Sent. we were not able to establish the reason yet why, this delay happened.
HTH,

Twilio SDK General error #31000

We use Twilio SDK in our iOS app. It works fine but sometimes didStopListeningForIncomingConnections callback is called with error=31000 ("General error"). After that, the device turns to a strange state: it seems to be online but it's impossible to call it. And it shows "unconnected" state on the device.
So the questions are:
1. What does this 31000 error means?
2. What should we do in such a case? How to reconnect device to Twilio?
Megan from Twilio here.
You can see what an error for Twilio Client means here: https://www.twilio.com/docs/api/client/errors
However, 31000 is a rather vague and less than ideal error message as you describe. In this case, it is likely that the Twilio capability token has probably expired while the application is in the background, and if you merely call the listen method whenever they are receiving the 31000 generic error, it might cause the client SDK to result in a error-retry loop and crash the application eventually.
At the time of your writing with TwilioClient iOS SDK v1.2.5, it is suggested to use the following sample code in your did-stop-listening callback:
- (void)device:(TCDevice*)device didStopListeningForIncomingConnections:(NSError*)error {
if ( [self checkCapabilityTokenStillValid] ) {
// if the token has not yet expired, use the `listen` method of `TCDevice` to resume the listening state
[self.device listen];
}
else {
// restart all over by requesting a new capability token and initialize/update the `TCDevice` instance again
[self login];
}
}
The TwilioClient iOS SDK takes care of dispatching the listen and updateCapabilitiyToken: methods to the current thread for execution, therefore it's safe to call them directly in the didStopListeningForIncomingConnections. The did-stop-listening delegate method is always triggered with dispatch_get_main_queue() of Grand Central Dispatch.
Hope this may help others if they run into the same generic error.
This may or may not be the issue, we have encountered 31000 errors two times in our development and both were a result of generating the JWT on our server api. To be clear the error was a 31000 on the client, but the reason for this was in the construction of the JWT, and the params we wanted twilio to send back to our application.
When passing in an object to allow_client_outgoing or allow_client_incoming the twilio sdk concats this all in their scope attribute in their JWT. It added it to the scope:client:outgoing?appSid= which looks like a query string. That means it has a size limit of 2048. So exceeding this length generates a 31000 error.
In addition adding the objects doesn't seem to always implicitly serialize the object correctly, it introduces characters that can generate errors in their corresponding mobile sdks (but not their web sdk ... weird) so we took care of this by explicitly serializing objects to JSON before they are inserted into the JWT.
I hope both of these examples help you track down the issue.

How does an iOS device identify itself to server without user log in

I am writing an iOS app with a Rails API backend. The Rails backend will serve JSON data to the app. I have the following requirements.
The app will be a free download
The app will show data on a map
The app will show data in the vicinity of the user
Upon loading the app the device should send some unique identifier to the server identifying itself as a device that is running this app.
There will be no authentication for the user as it is not required. The data is available to anyone who downloads the app. All the server needs to know is that the client is a device running the app. The server cannot serve data to any other client
I would like to run the data using SSL between the device and server
The user location will be sent to the server and the server returns the corresponding pieces of data that are in the vicinity of the user
The client receives the JSON and caches the data locally.
Question: Given these requirements, how to set up steps 4 & 5?
Also: If I want to search more on this topic what keywords should I be googling for?
Consider using OpenUDID or SecureUDID.
I give you 2 options.
First of all, the easy way. From some time, apple forbids access to the device ID. However, they give you a device token instead.
To get this unique token, the user must register for remote notification.
Upon application launching, call the following function:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
Then this callback will be called:
- (void)application:didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken.
Send the token to your server and you're done. Problems with this approach are obvious. Your user will have to register for remote notification.
Another approach is to use the MAC address of the wi-fi board.
To do this:
IPAddress.h
IPAddress.c
Import this files into your project.
Then use this function:
InitAddresses();
GetHWAddresses();
for (int i=0; i<MAXADDRS; ++i)
{
//There is a way you can obtain more info about the hw_addrs, but in general, it's the first.
NSLog(#"MAC: %s", hw_addrs[i]);
}
FreeAddresses();
Create a hash using the mac address above and you're done.
Hope it helps.
Upon first launch, the app sends a request to the server saying Hi, I'm a new client, give me an id! The server generates a new, random id and sends it back. The app saves the id locally and uses it henceforth to uniquely identify itself.

Can I get response for POST method (Restful)?

I want to make some request from iPhone app to my web service (Rails) and when is data procesed to get response with some string for example.
I read a lot about Apple's push notifications, but I need answer immediately and push notification can late.
I made POST request to my Rails app from my iPhone app, and it works.
First question(I got answer): But, can I get some string as response from Web service (Rails app)?
Second question: When I got request from iPhone app, how to notifies some iPad device for example (with running app) quickly from my Rails web app? One solution is push notification, is there something faster and safer?
If you just want a text string you could do render :text => 'Some string'. If you want/need a more structured response then you should respond with JSON or XML.

Resources