I am an iOS developer & currently working on an app in Kony studio. I have to send iOS device token on server for Push notification via a json service. Is there any way/api in kony studio to get iOS device token?
Any help or idea would be great for me.
Thanks.
Here is what I am using in my Kony Studio project:
subscriptionArguments.deviceId = kony.os.deviceInfo().identifierForVendor;
We are using Kony visualizer 7.x. And use the code as below to register the device for push notification.
try {
setStatus("Getting device info.."); //Own function
messagingClient = client.getMessagingService();
var osType = "";
if(kony.os.deviceInfo().name=="iphone" || kony.os.deviceInfo().name=="iPhone"){
osType = "iphone";
}else{
osType = "androidgcm";
}
var deviceInfo = kony.os.deviceInfo();
var deviceId = deviceInfo.deviceid;
var userId = emailId;
messagingClient.register(osType,deviceId,deviceRegID,userId,pushSubscriptionSuccessCallback,pushSubscriptionErrorCallback);
setStatus("Subscribing..");
}catch (e) {
kony.print("Error while subscribing the device " + e);
}
Hope this helps!
var deviceInfo = kony.os.deviceInfo();
var deviceID=deviceInfo.deviceid;
Above Code will give device ID for anddroid, but for IOS it will give 02:00:00:00:00:00, which is not helpful.
You can do it using below code for IOS.
var deviceID= deviceInfo.identifierForVendor;----for and above 6.0 and
var deviceID= deviceInfo.customdeviceid;----- below 6.0
Reference: http://docs.kony.com/5_6_PDFs/Kony_API_Reference_Guide.pdf
Related
Build environment:
Macbook M1
vscode(1.69.0) as well as vs2022 (17.3)
Steps to reproduce:
create new Maui app
add nuget package "Microsoft.Extensions.Http" Version="6.0.0" to project
Modify MauiProgram.cs:
builder.Services.AddHttpClient<EndPointAHttpClient>(client =>
{
var EndPointA = "https://www.montemagno.com/";
client.BaseAddress = new Uri(EndPointA);
});
public class EndPointAHttpClient
{
public EndPointAHttpClient(HttpClient client)
{
Client = client;
}
public HttpClient Client { get; }
}
Publish:
dotnet publish <project.csproj> -f:net6.0-ios -c:Release /p:ServerAddress=<xxx.xxx.xxx.xxx> /p:ServerUser=user /p:TcpPort=58181 /p:ServerPassword=pwd -p:AotAssemblies=false
Install on iphone using Transporter/TestFlight
CRASHES WHEN OPENING THE APP
Please let me know:
1. Is there any demo code that works
2. Kindly provide advise on how I can use HttpClient in a .net Maui app
Use the code found here. https://github.com/dotnet/maui-samples/tree/main/6.0/WebServices/TodoREST/TodoREST/Services
Grab the RestService, IRestService, HttpsClientHandlerService and IHttpsClientHandlerService.
Get the Contstants file as well.
https://github.com/dotnet/maui-samples/blob/main/6.0/WebServices/TodoREST/TodoREST/Constants.cs
Makes sure you add your Url to the HttpsClientHandlerService like so. I was getting a System.Net.WebException: Error: TrustFailure. The only way I was able to catch what was happening was using Sentry.io. I guessed that this might be the problem.
public bool IsSafeUrl(NSUrlSessionHandler sender, string url, Security.SecTrust trust)
{
if (url.StartsWith("https://localhost") || url.StartsWith("https://yourservice.azurewebsites.net"))
return true;
return false;
}
Then change this line.
var handler = new NSUrlSessionHandler
{
TrustOverrideForUrl = IsSafeUrl
};
8/3/2022 13:40:32 NotImplementedError: This is not implemented yet. For currently supported API, see: https://developers.google.com/google-ads/scripts-beta/docs/reference/adsapp/adsapp
at Ha (adsapp_compiled:298:11)
at new $y (adsapp_compiled:13027:5)
at qC.newVideoAd (adsapp_compiled:15250:12)
at Object.<anonymous> (adsapp_compiled:18396:54)
var youtubeVideoId = "youtubeVideoId";
var adGroupName = "adGroupName" // name of my target video ad group
var displayUrl = "display-url.com";
var finalUrl = "https://final-url.com";
var assetOperation = AdsApp.adAssets().newYouTubeVideoAssetBuilder()
.withName(adName)
.withYouTubeVideoId(youtubeVideoId)
.build();
var videoAsset = assetOperation.getResult();
var videoAdGroup = AdsApp.videoAdGroups()
.withCondition(`Name = '${adGroupName}'`)
.withLimit(1)
.get()
.next();
var videoAdOperation = videoAdGroup.newVideoAd().inStreamAdBuilder()
.withVideo(videoAsset)
.withAdName(adName)
.withDisplayUrl(displayUrl)
.withFinalUrl(finalUrl)
.build()
.getResult();
// Code crash before next statement
if(videoAdOperation.isSuccessful()) {
var videoAd = videoAdOperation.getResult();
Logger.log("VideoAd " + videoAd.getName() + " created.");
} else {
Logger.log(videoAdOperation.getErrors());
}
Code breaks after videoAdGroup.newVideoAd().inStreamAdBuilder().
Following the google ads script docs everything should works nice.
But when I compile the script, I always get the next error:
I have just found in a Google ads scripts forum somebody who has the same problem here but no solution.
The problem is that beta mode which is active by default. Must be switched off for this action.
As a negative point, switch off Beta mode will not allow you to use javascript arrow functions, neither js classes.
I was following this tutorial: https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management
So I wrote some test send code looks like:
void TestSend(bool ios)
{
var AzureName = "myhubname";
var AzureHub = new ServiceBusConnectionStringBuilder("Endpoint=sb://secret+sauce").ToString();
var tags = new List<string>();
tags.Add("doopy");
try
{
var svcs = new ServiceBusConnectionStringBuilder(AzureHub).ToString();
var hub = NotificationHubClient.CreateClientFromConnectionString(svcs, AzureName);
// what is this?
// var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var installation = new Installation(); // control tag registration
// FCM - works
installation.Platform = NotificationPlatform.Fcm;
installation.PushChannel = "put my fcm token here";
installation.InstallationId = "see comment..."; // from the device via this call: myNotificationHub.Register(FCMToken, new List<string>().ToArray()).RegistrationId;
if (ios)
{ // silently fails
installation.Platform = NotificationPlatform.Apns;
installation.InstallationId = "some guid I made up";
installation.PushChannel = "see comment"; // device token with <> and spaces removed from call mySBNotificationHub.RegisterNativeAsync(deviceToken...
}
installation.Tags = tags;
hub.CreateOrUpdateInstallationAsync(installation).Wait();
JObject data = MakeNotification("notificationId", "I got your tags doopy!");
var payload = PlatformPayload(ios, data);
Console.WriteLine("Send...");
if (ios)
hub.SendAppleNativeNotificationAsync(payload, tags).Wait();
else
hub.SendFcmNativeNotificationAsync(payload, tags).Wait();
Console.WriteLine("Message SENT!");
}
catch (Exception ex)
{
Console.WriteLine("rats! " + ex.Message);
}
}
I don't even use the mystery PushNotificationChannelManager from the docs and FCM works. That class seems to only exist in UWP or something.
It seems that APNS requires both an installation ID and a channel, but all I have is a device Id. Anyone know where to get these values for iOS?
So I have found a solution.
Take the iOS device token, remove spaces and angle brackets and use that for PushChannel. Create your own InstallationId (Guid.NewGuid().ToString(); and save it somewhere) or just use the device token for both fields.
I am trying for a while now to implement this flow: When user adds some files on server app, notification should trigger and send from server to FCM and that from there to pass message saying something like: 'New file has been added'.
Basically I want to inform mobile device user that something on server has been changed.
I have tried many things, but nothing seems to work as I would expect, at least.
On the mobile side I have set up Firebase inside my Xamarin.Android project, and when I am sending notifications directly from Firebase console, I get notifications, and everything is good.
But I don't want to send notifications via Firebase console, I would rather send notification from server (which is ASP.NET MVC project) to Firebase console and then pass it from there to android device.
My first question would be: Has anybody got an idea how can I inform web app about device_id? Is there some way that android device send this information on server? And maybe from there I can store that data and update it occasionally, since it is basically a refresh token.
My second problem is this: Even when I hard code current device_id of an active android device and try to send a message from server whit this code:
public class FirebaseService : IFirebaseService
{
public void SendMessageToClientApplication(string message, string serverApiKey, string senderId, string deviceId)
{
AndroidFCMPushNotificationStatus result = new AndroidFCMPushNotificationStatus();
try
{
result.Successful = false;
result.Error = null;
deviceId = "eMk6mD8P8Dc:APA91bG5Lmqn4Hwb4RZJ1Mkdl8Rf_uYQsQCEfDJK334tzSvIGzdao7o2X6VmtcTEp_Li0mG8iUoUT7-_RnZxQKocHosZwx6ITWdpmQyCwUv60IIIy0vxNlEaccT6RqK6c-cE1C6I3FTT";
var value = message;
WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
tRequest.Method = "post";
tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", serverApiKey));
tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));
string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
+ value + "&data.time=" + DateTime.Now.ToString() + "®istration_id=" + deviceId + "";
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
result.Response = sResponseFromServer;
}
}
}
}
}
catch (Exception ex)
{
result.Successful = false;
result.Response = null;
result.Error = ex;
}
}
}
I get nothing both in Firebase console and of course nothing on device as well.
I have tried to implement Firebase web as javascript on my server app like this:
<script>
var config = {
apiKey: "mykey",
authDomain: "myauthdomain",
databaseURL: "mydatabaseurl",
projectId: "myprojectid",
storageBucket: "mystoragebucket",
messagingSenderId: "mysenderid"
};
window.onload = function () {
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function () {
console.log('Notification permission granted.');
return messaging.getToken()
})
.then(function (token) {
console.log(token);
})
.catch(function (err) {
console.log('Unable to get permission to notify.', err);
});
messaging.onMessage(function (payload) {
console.log('onMessage: ', payload);
});
}
</script>
But this code gets some kind of a different device_id(aka token), probably one generated for that server machine.
Does anybody has experience with sending device_id to server app and from there sending notification message to Firebase console? I would appreciate some code examples, tutorials or anything that can help, since I was unable to find something useful during my google search.
My first question would be: Has anybody got an idea how can I inform web app about device_id?
The most common approach is to store the list of device tokens (each device that uses FCM has such a token) in a database, such as the Firebase Database. There is an example of this in the Cloud Functions for Firebase documentation. In this example the devices receiving the messages are web pages, but the approach is the same for iOS and Android.
I also recommend reading Sending notifications between Android devices with Firebase Database and Cloud Messaging. In this article, instead of sending to a device token, each user subscribes to a topic. That prevents having to manage the device tokens in your code.
In my app i want to get the device uuid or udid so that i can save it in my database.
for my android app when i run this code in my js file
.factory('Service', function($state) {
var service = {
login: function(user, new_device_status) {
if(window.cordova) {
var params = {
organization: user.orgCode.$modelValue,
email: user.email.$modelValue,
password: user.password.$modelValue,
device_uuid: window.device.platform == 'Android' ? window.device.uuid : window.device.udid,
new_device: new_device_status
};
}
}
}
})
it works and returns the uuid of the device but in my ios app when i try this it doesnt work or when i try
window.device.udid
it still doesnt work in my ios simulator. what can i do?
Solution 1 :
Add device plugin :
cordova plugin add org.apache.cordova.device
In your controller :
module.controller('MyCtrl', function($scope, $cordovaDevice) {
var uuid = $cordovaDevice.getUUID();
});
Answer from : How to get the device UUID in ionic framework
Solution 2 :
Use IDFVPlugin :
cordova plugin add https://github.com/jcesarmobile/IDFVPlugin.git
In your controller :
window.IDFVPlugin.getIdentifier(function(result){
alert(result);
},function(error){
alert(error);
});
Sources :
https://github.com/jcesarmobile/IDFVPlugin
http://forum.ionicframework.com/t/how-to-get-iphone-unique-id-udid-in-ionic-framework-script/9575
I hope it will help you.
but be aware, the UUID is not the same thing as the UDID.
Differences between UDID and UUID
the UUID is the app specific id that changes when you remove the app or update it sometimes even, and the UDID is the unique id from the phone itself.