How to configure Push Notification in Mobile App Buider? - ios

I'm using a Mobile App Builder to make some prototype. One of them I need to send push notification. So, I created a App with App Builder and configure a push settings using Push Notification Services (App GUID and App Route).
After that, I was defined settings a Apple Certificate to send push (https://new-console.ng.bluemix.net/docs/services/mobilepush/t_push_provider_ios.html)
So, when I try to send push notification using Push Notification Services (Bluemix) I receive a msg:
1 - Internal server error. No devices found.
When I see a log in XCode I Found:
registerDeviceToken:completionHandler:]_block_invoke_2 in IMFPushClient.m:116 :: Response of device registration - Response is: httpStatus: 201
responseHeaders: {
Connection = "Keep-Alive";
"Content-Type" = "application/json";
Date = "Thu, 12 May 2016 18:21:22 GMT";
Location = "https://enviarpush.mybluemix.net:443/imfpush/v1/apps/428e6b13-2cc7-4f99-8d7e-9741d6742709/devices/AFAF9994-535D-4F6C-9789-317E680833A8";
"Transfer-Encoding" = Identity;
"X-Backside-Transport" = "OK OK";
"X-Global-Transaction-ID" = 2301423703;
"X-Powered-By" = "Servlet/3.0";
}
responseJson: {
createdMode = API;
createdTime = "2016-05-12T18:21:22Z";
deviceId = "AFAF9994-535D-4F6C-9789-317E680833A8";
href = "https://enviarpush.mybluemix.net:443/imfpush/v1/apps/428e6b13-2cc7-4f99-8d7e-9741d6742709/devices/AFAF9994-535D-4F6C-9789-317E680833A8";
lastUpdatedTime = "2016-05-12T18:21:22Z";
platform = A;
token = 7574a3f1d14a7a01f8d43663cef686b3cb66a634b71ed20608a739c4f55356db;
userId = "";
}
Response text: {"createdTime":"2016-05-12T18:21:22Z","lastUpdatedTime":"2016-05-12T18:21:22Z","createdMode":"API","deviceId":"AFAF9994-535D-4F6C-9789-317E680833A8","userId":"","token":"7574a3f1d14a7a01f8d43663cef686b3cb66a634b71ed20608a739c4f55356db","platform":"A","href":"https://enviarpush.mybluemix.net:443/imfpush/v1/apps/428e6b13-2cc7-4f99-8d7e-9741d6742709/devices/AFAF9994-535D-4F6C-9789-317E680833A8"}
This infos confirm that my device was register, I'm right?
Thanks

Moving forward we will be integrating the device registration, for the period we are experimental we will be creating a number of blog posts that explain some of the key integration you will need to do manually in code. This will include how we recommend integrating with a bluemix backend.

You have to register a device to the IBM Push Notifications Service in order for it to successfully receive push notifications. I would suggest looking at the following documentation:
Enabling iOS applications to receive push notifications
There is also a sample available that demonstrates these capabilities:
HelloPush

Related

How to send push certificate to APNS while calling their APIs?

Have been stuck for sending push notification using apns push certificate from my server app (Spring Boot Application). Apple discussed here on an overview of how we can send push with certificate but there is no technical detail about TLS communication (specially, on how I can send my push certificate to APNS and proceed API calls).
Anyone have any reference or article?
Since you mentioned your working on a Spring Boot application I'm assuming you're using Java and Maven.
Our back ends are also written in Java and I recently updated our push notification code by implementing Pushy. It's much much easier to use a library that's battle tested and regularly updated than to write your own. I use pushy to send around 100k push notifications a day on a fairly weak server and have never had any issues with it.
It was fairly simple to implement. Their README is very useful but the summary is add pushy as a dependency in your pom.xml file:
<dependency>
<groupId>com.eatthepath</groupId>
<artifactId>pushy</artifactId>
<version>0.13.11</version>
</dependency>
Here's a simple example for your use-case using stolen code from the README, I did add the comment though:
// Add these lines as class properties
// This creates the object that handles the sending of the push notifications.
// Use ApnsClientBuilder.PRODUCTION_APNS_HOST to send pushes to App Store apps
final ApnsClient apnsClient = new ApnsClientBuilder()
.setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST)
.setClientCredentials(new File("/path/to/certificate.p12"), "p12-file-password")
.build();
// The push notification
final SimpleApnsPushNotification pushNotification;
// In some method:
// Creating the object that builds the APNs payload
final ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder();
// setting the text of the push
payloadBuilder.setAlertBody("Example!");
// Builds the anps payload for the push notification
final String payload = payloadBuilder.build();
// The push token of the device you're sending the push to
final String token = TokenUtil.sanitizeTokenString("<efc7492 bdbd8209>");
// Creating the push notification object using the push token, your app's bundle ID, and the APNs payload
pushNotification = new SimpleApnsPushNotification(token, "com.example.myApp", payload);
try {
// Asking the APNs client to send the notification
// and creating the future that will return the status
// of the push after it's sent.
// (It's a long line, sorry)
final PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification);
// getting the response from APNs
final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = sendNotificationFuture.get();
if (pushNotificationResponse.isAccepted()) {
System.out.println("Push notification accepted by APNs gateway.");
} else {
System.out.println("Notification rejected by the APNs gateway: " +
pushNotificationResponse.getRejectionReason());
if (pushNotificationResponse.getTokenInvalidationTimestamp() != null) {
System.out.println("\t…and the token is invalid as of " +
pushNotificationResponse.getTokenInvalidationTimestamp());
}
}
} catch (final ExecutionException e) {
System.err.println("Failed to send push notification.");
e.printStackTrace();
}

iOS13 apns-push-type header on azure notification hub

Starting from iOS 13 and watchOS 6 Apple requires the presence of the header apns-push-type (the value of this header can be alert or background) for push notification.
According to Apple documentation:
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.
HEADERS
- END_STREAM
+ END_HEADERS
:method = POST
:scheme = https
:path = /3/device/xxxxxx
host = api.sandbox.push.apple.com
authorization = bearer xxx
apns-id = xxx-xxx-xxx
apns-push-type = alert
apns-expiration = 0
apns-priority = 10
apns-topic = com.example.MyApp
DATA
+ END_STREAM
{ "aps" : { "alert" : "Hello" } }
see Apple doc
Unfortunately using azure notification hub I can only define apscontent but not the header.
{ "aps": { "alert":"Alert message!", "content-available": 1 }, "CustomData": "$(CustomData)" }
How is it handled by azure notification hub?
How can I specify the type of the notification?
After some experiments and a little bit of investigation, this is the current Azure server behavior...
The server inspects the contents of the notification to infer the correct value.
If "content-available": 1 is present and "alert" is missing then the "apns-push-type" = "background" is added to the header.
If a valid "alert" is present then the "apns-push-type" = "alert" is added to the header.
So take care of having a valid APNS JSON body, with correctly populated content-available/alert properties.
See this discussion thread for more info
UPDATE 2019-10-15:
Currently there are some problems with background silent notification
See the following discussion:
https://github.com/Azure/azure-notificationhubs-dotnet/issues/96
UPDATE 2019-11-25:
The server was rejecting installations against APNS that included headers. Now this issue is fixed and the silent notification should work as expected.
This answer is not accurate, background push is not working on azure right now. The headers need to be included during sending a push as shown below and also the hub needs to be configured with a key and not a certificate:
var backgroundHeaders = new Dictionary<string, string> { { "apns-push-type", "background" }, { "apns-priority", "5" } };
Dictionary<string, string> templateParams = new Dictionary<string, string>();
// populated templateParams
var notification = new TemplateNotification(templateParams);
notification.Headers = backgroundHeaders;
// the second parameter is the tag name and the template name as we have it registered from the device.
var resBack = await hubClient.SendNotificationAsync(notification, tags);

Mobile First - Unable to Register Device for Push Notification

It seems i am not able to register my iOS device on a remote server(MobileFirst Platform Server) that is being hosted for push notification.
Here is my code for registering the device
MFPPush.registerDevice(
{},function(successResponse) {
},
function(failureResponse) {
alert("Failed to register "+failureResponse);
});
I'm always getting a fail response which is
"Error Domain=com.ibm.mfp.push Code=5 \"Request failed: internal server error (500)\" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x156663e80> { URL: http://<server-ip:port>/imfpush/v1/apps/<app-bundleidentifier>/devices/FFF2867D-D43A-4FC0-A9C7-CBECF26BFFD6 } { status code: 500, headers {
Connection = Close;
\"Content-Length\" = 0;
\"Content-Type\" = \"application/json\";
Date = \"Mon, 20 Mar 2017 03:57:45 GMT\";
\"X-Powered-By\" = \"Servlet/3.0\";
}}, NSErrorFailingURLKey=http://<server-ip:port>/imfpush/v1/apps/<app-bundleidentifier>/devices/FFF2867D-D43A-4FC0-A9C7-CBECF26BFFD6, com.alamofire.serialization.response.error.data=<>, NSLocalizedDescription=Request failed: internal server error (500)}"
Other information:
My server ip is http://52..:9080
I have set up "push.mobileclient" scope with custom security check, i have also set up "push.application.app-bundleidentifier" and "messages.write" at Confidential Clients
I have uploaded the apns-certificate-sandbox.p12 cert too for the app for MobileFirst server
The registration is successful when I'm registering against localhost.
I hope the data provided is sufficient.
thanks in advance
I have manage to solve this by updating the server and client mobile first platform version to the same one.

IBM-Bluemix Push Service on iOS crashes app when first registering with the service

I'm using the new push-notification service on bluemix, with an iOS device.
The device registers successfully. When I check with the REST-API, I see the device-ID, token and so on.
However, running the iOS-app on the device crashes the app on first run and registration.
The crash happens in CDVMFPPush.swift in func didRegisterForRemoteNotifications(deviceToken: NSData)
on line 309 (let pushToken = response.responseJson["token"] as! String).
I did a print(response) in this function and it seems that responseJson only contains the deviceId and the userId. The token is missing.
When I use the REST-Api again to do the same request, the response seems to be complete.
I think that because of this error the push registration doesn't finish, as I don't receive any notifications when I try to run the service in sandbox-mode.
Any ideas?
(P.S. I checked this solution - iOS Application crashes when trying to register the device to IBM Mobile First Push service on Bluemix - the linker flag is set [-ObjC])
Here's the request from my console (app-id/secret/device is edited)
Response text: {"createdTime":"2016-06-07T15:28:55Z","lastUpdatedTime":"2016-06-07T15:28:55Z","createdMode":"API","deviceId":"xxxx","userId":"","token":"xxxx","platform":"A","href":"https://myapp.mybluemix.net:443/imfpush/v1/apps/xxxx/devices/xxxx"}
httpStatus: 201
responseHeaders: {
Connection = "Keep-Alive";
"Content-Type" = "application/json";
Date = "Tue, 07 Jun 2016 15:28:55 GMT";
Location = "https://myapp.mybluemix.net:443/imfpush/v1/apps/xxxx/devices/xxxx";
"Transfer-Encoding" = Identity;
"X-Backside-Transport" = "OK OK";
"X-Global-Transaction-ID" = xxxx;
"X-Powered-By" = "Servlet/3.0";
}
responseJson: {
deviceId = "xxxxx";
userId = "";
}
We've updated the MFPPush iOS Framework to resolve the issue and the MFPPush Cordova Plugin has been updated to incorporate these fixes. We suspect the crashes were caused by the fact that you were being sent a second IMFResponse object through the callback and this second IMFResponse's responseJson didn't have the token as you saw which was resulting in the crash. These changes should resolve that issue.
Easiest way to update the plugin is just to remove the old and re-add it, you should be on version 1.0.14 of ibm-mfp-push to see the fixes.
Can see the update on the related Github as of this morning as well
https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push

Silent Authentication in Actionscript without generating the dialog box

I need to send the device token required for push notification in iOS to urban-airship server from the actionscript code. How can i do that? I am using their API's in my app. I am just using urban-airship to test push notifications on my app.
Since their url requires user authentication, I want to write code so that authentication happens silently without generating the pop dialog.
I finally figured out myself how to solve this problem:
// AIR developer can send the tokenId received in event.data to his server via URL request
var urlRequest:URLRequest;
var urlLoader:URLLoader = new URLLoader();
var tokenId:String; //tokenId received after registering for push notifications
var urlString:String = "https://go.urbanairship.com/api/device_tokens/" + tokenId;
urlRequest = new URLRequest(urlString);
urlRequest.authenticate = true;
urlRequest.method = URLRequestMethod.PUT;
URLRequestDefaults.setLoginCredentialsForHost("go.urbanairship.com",<userId>,<password>) ;
urlLoader.load(urlRequest);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onStatus);

Resources