How to get mobile reistration ID using GSM Titanium? - titanium

I am developing android app in titanium,by button click event I have to get registration ID from GCM. how to do that I am new to titanium.
I followed this http://iamyellow.net/post/40100981563/gcm-appcelerator-titanium-module, but I am not able to understand how to implement?
Thanks in advance.

To implement push notification, you should use Ti.CloudPush module.
You can achieve GCM Push Notification in 6 easy steps
Setting up Google Cloud Messaging
Push Configuration in ACS Console
CloudPush Module Implementation
Retrieve Device Token
Cloud User Login
Subscribe a Channel
1. Setting Up GCM
To use GCM, you need to create a Google API project to obtain a Google API key and GCM sender ID. For instructions on creating and obtaining these items, see Android Developer: Getting Started with GCM and follow the directions in "Creating a Google API Project", "Enabling the GCM Service" and "Obtaining an API Key".
We will use our Project number as GCM Sender ID.
When creating a new server key, you are asked for a list of IP addresses to accept requests from. Do not enter any information in the textbox and click Create to accept all IP addresses.
2. Push Configuration in the ACS
Go to your apps, then go to My Apps -> Manage ACS -> DEVELOPMENT -> Settings/Android Push Configuration and enter your Google API key in the Google Cloud Messaging (GCM) API Key textbox and GCM sender ID in the Google Cloud Messaging (GCM) Sender ID textbox. (which we got from Step 1)
3. CloudPush Module Implementation
Add CloudPush module into your application.
To add CloudPush module, you need to add <module platform="android">ti.cloudpush</module> in your TiApp.xml. Then require the module in your javascript file using var CloudPush = require('ti.cloudpush');.
To use push notifications, in the tiapp.xml file, you need to specify push type to GCM.
To do this go to your tiapp.xml.
Add/edit the following lines
<property name="acs-push-type-development" type="string">gcm</property>
<property name="acs-push-type-production" type="string">gcm</property>
<property name="acs-push-type" type="string">gcm</property>
4. Retrieve Device Token
Call the retrieveDeviceToken method before setting the enabled property to true to enable the device to receive push notifications. You must call retrieveDeviceToken before any other CloudPush API call or else the device will not receive push notifications.
var CloudPush = require('ti.cloudpush');
var deviceToken = null;
CloudPush.retrieveDeviceToken({
success: function deviceTokenSuccess(e) {
Ti.API.info('Device Token: ' + e.deviceToken);
deviceToken = e.deviceToken;
},
error: function deviceTokenError(e) {
alert('Failed to register for push! ' + e.error);
}
});
5. Cloud User Login
Before subscribe for Push Notification, cloud user should logg in.
Cloud.Users.login({
login: username,
password: password
}, function (e) {
if (e.success) {
alert("login success");
} else {
alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
}
});
6. Subscribe a Channel
You need to subscribe to a channel to get the pushnotification. Push notification will be sending to the particular channel and it will be reached to all users who subscribed to the channel.
if(deviceToken != null){
Cloud.PushNotifications.subscribe({
channel: 'yourchannelName',
device_token: deviceToken,
type: 'gcm' //here i am using gcm, it is recommended one
}, function (e) {
if (e.success) {
alert('Subscribed for Push Notification!');
} else {
alert('Subscribe error:' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
alert('You need to retrieve the device token first');
}
Now you can send push notification. To do this go to My Apps -> Manage ACS -> DEVELOPMENT -> Push Notifications, here you can see number of clients subscribed for push notification, channels etc. You can send the push notification from there.
UPDATE : Attention!!
GCM supports devices that run Android 2.2 and later
Google Play Store application should be installed in your device.
For pre-4.0 devices, the user is required to set up their Google account.
You're using an android device for testing, not emulator(Since you can't install Google Play in your emulator).
Google play service is running on your device.
The following links will help you:
Titanium.CloudPush
Android SDK Titanium
ACS Push Notification Using GCM

Related

Twilio programmable chat message user friendlyName

I am using Twilio Programmable Chat to add a chat feature to my mobile app built in React Native. I'm using the JS client SDK for this.
When the app receives a new message, the data that comes through uses the user identity for the author field. Is there away to include the friendlyName in the payload so I can display this to the user.
I could make a separate request for all users and find the correct user within the app but it would be great if this data could just be on the same request.
Thanks for any help
Yes, only author field present in new message event, I used an alternate approach
channelMembersDict = {}
// Assuming you have set selected an Channel
this.activeChannel.getMembers().then(members => {
members.forEach(mem => {
//member contains friendlyName attribute
this.channelMembersDict[mem.state.identity] = mem;
//If you really want user then
mem.getUser().then(user => {
this.channelMembersDict[mem.state.identity] = user;
});
});

Unable to Register IOS device to Mobile First 8

I am able to see the iOS device under devices tab in MF, registered to my application. but pushing a notification fails with the below error:
An error occurred while the notification was sent. Internal server error. No devices found.
Upon reviewing IOS code, I noticed the below issue while invoking MFPPush.sharedInstance.registerDevice(nil)
Cannot retrieve a valid authorization header for header. Check resource and authorization server configuration.
I am using the code from the git sample. Below is the snippet throwing the error:
#IBAction func registerDevice(_ sender: AnyObject) {
print("Attempting Device registration with Mobile First")
WLAuthorizationManager.sharedInstance().obtainAccessToken(forScope: "push.mobileclient") { (token, error) -> Void in
if (error != nil) {
print("Did not recieve an access token from server: " + error.debugDescription)
} else {
WLClient.sharedInstance()?.setDeviceDisplayName("White Ipad", withCompletionHandler: { (error) in
if error == nil{
print("device display name is set")
}else{
print("error setting device name: " + error.debugDescription)
}
})
print("Recieved the following access token value: " + (token?.value ?? "no token"))
MFPPush.sharedInstance().registerDevice(nil) { (response, error) -> Void in
if error == nil {
self.enableButtons()
self.showAlert("Registered successfully with Mobile First")
print(response?.description ?? "")
} else {
self.showAlert("Registration failed with Mobile First. Error \(error?.localizedDescription)")
print(error?.localizedDescription ?? "")
}
}
}
}
}
Mobile First Config: I have followed the documentation and configured the UserLogin security check from the sample git project and have removed scope to push.mobileclient under security.
Reading the OAuth Security in MF, i understand the that token is necessary to access resources, but I am unable to figure out how to attach the token in registerDevice().
It seems to be you haven't configured Push Notifications properly in MobileFirst Server.
Make sure that you have added push.mobileclient scope in Security tab of your application. If you are not using any security check, you can add scope like below.
Check whether your application is configured valid iOS provisioning profile enabled with Push Capability
Make sure that you have uploaded valid sandbox/production certificates in Push tab of your particular app in MFP Operations Console.
More details : here
Make sure your app is enabled Push Capability in the project setting and also check you sending device token to MF Server using MFPPush.sharedInstance().sendDeviceToken(deviceToken) API in didRegisterForRemoteNotificationsWithDeviceToken method of AppDelegate file
-

Sending a link using push notifications in Azure for Android

I have created a backed in asp.net web-forms successful send a notification for all registered devices but I tired to send a link for example I need to send one push notification include a link When user touch on the notification redirect to mobile browser and open the link.
private static async void SendNotificationAsync()
{
NotificationHubClient hub = NotificationHubClient
.CreateClientFromConnectionString("<Here is my endpoint >", "<hub name>");
await hub.SendGcmNativeNotificationAsync("{ \"data\" : {\"message\":\"Hello Users \"}}");
}
Based on my experience, we could use custom json format and at receiver end convert that string into url. For example,Here’s a sample of the complete JSON payload with a custom "web_link" key containing the URL:
{"data": "{\"message\":\"xxxx\",\"web_link\":\"https://www.example.com\"}"}
Then we could override the OnMessage function to create Notification, we also could get more detail info from the Azure document.

How do I deregister device in MFP

I am sending push notification via an external script and capturing the response that is return from MobileFirst. The response is always 200 and a messageId is in the response JSON object
How can I simulate a error condition?
I used the MFP API to remove the subscription, removing the device from the device tab in the MFP console. However, I can still send and receive push notification for that deviceID .
Unsubscribing from the tag subscription (which you have subscribed in the code) does not clear all subscriptions. A default Push.ALL tag subscription stays in the DB. This is why you are able to still send notifications.
You can remove the device registration either using the SDK ( as mentioned by Gaurab) or use the REST API call to do this.
Details here: Push Device Registration Delete
I assume that you are using IBM MobileFirst v8.0.
You need to implement these API in client side to unregister the device or unsubscribe from tags.
Unregister the device from push notification service instance.
MFPPush.unregisterDevice(
function(successResponse) {
alert("Unregistered successfully");
},
function() {
alert("Failed to unregister");
}
);
Unsubscribe from tags.
var tags = ['sample-tag1','sample-tag2'];
MFPPush.unsubscribe(
tags,
function(tags) {
alert("Unsubscribed successfully");
},
function() {
alert("Failed to unsubscribe");
}
);

Apple Push Notifications not arriving on iOS device from Microsoft Azure Notification Hub

I have followed-up the tutorial Microsoft Azure Notification Hub for iOS apps till the end and successfully registered device for push notifications. When I send a test notification from Debug option in Azure Classic Portal the Result shown with options Registration ID (XXXXXX12345), Platforms (apple) and Outcome says "The Notification was successfully sent to the Push Notification System" but my device is not receiving any Notifications. I have uploaded a valid .p12 certificate into Azure Portal as well. I am using azuresdk-iOS-v1.2.4 framework with iOS 9. Please help me on it.
SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBLISTENACCESS notificationHubPath:HUBNAME];
[hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
if (error != nil) {
NSLog(#"Error registering for notifications: %#", error);
}
else {
[self MessageBox:#"Registration Status" message:#"Registered"];
}
}];
Do I need to covert deviceToken into Hexadecimal? right now am passing deviceToken as it is what am getting in didRegisterForRemoteNotificationsWithDeviceToken method.