It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
i am developing the BlackBerry app in which the data comes from the web services.The data contains the phone numbers of the different countries and also there is call functionality in the app.
I have used ActiveRichTextField to display data in labelfield so that phone numbers and email id's can be detected.It also detects the numbers and mail id's but it fails to detect some of the numbers.Do any body know how to detect number such as +618 12345678/79 and sort of the data.Any sort of help is appreciated.
If you are looking to recognise a string in another given string, you want to look at PatternRepository. This is a system managed collection of strings, that is used to add context menus to given strings.
If your string is found on the device, it will show the menu that you define. So you need to subclass ApplicationMenuItem and provide your own run() method.
The following code will set up your device to recognise a regular expression, and create a context menu item for when that pattern is found:
// MyAppMenuItem extends ApplicationMenuItem
MyAppMenuItem appMenuItem = new MyAppMenuItem(0);
ApplicationMenuItem[] applicationMenu = new ApplicationMenuItem[1];
applicationMenu[0] = appMenuItem;
// register the pattern to identify the phone number
PatternRepository.addPattern(
ApplicationDescriptor.currentApplicationDescriptor(),
"*** REGEXP String to recognise phone numbers ***",
PatternRepository.PATTERN_TYPE_REGULAR_EXPRESSION,
applicationMenu);
I found that this does not work in HTML fields (BlackBerry - intercept text in HTML). But it worked in almost all other places across my app, and in other apps, like email. If you only want it to work in your app, you can deregister this pattern when your app exits.
Note that you can add many different patterns to the PatternRepository - one for each style of number or email address that you want to recognise.
Related
I've found out that it's faster to get a reply here than in Twilio's support, so here it goes: I need to ask the user 3 questions, however, if the first answer is yes, there will be an extra question right on the spot.
Is it possible to do it on the same Collect?
Thank you.
Twilio developer evangelist here.
You can't do that within the same collect as there is no inherent logic in the flow through the JSON.
In my experience, if I needed a conversation to branch at some point that would be the end of one collect and I would start a new one based on the response. You can still remember all of the details throughout the conversation using the remember function.
Please provide snippets but I shall attempt to answer the question to the best of my ability.
If you are referring to the programmable chat function, I would also need to see the language you are using, although:
Create a variable, after asking the question, assign the variable to read the input, here's a basic example in VB.NET:
Dim ans As String
Console.WriteLine("Question")
ans = Console.ReadLine()
if (ans = "y")
{
Console.WriteLine("Different Question depending on the scenario")
}
if (ans = "n")
{
Console.WriteLine("Next Question")
Recursion()
/* Recursion the question that both y/n will both have*\
}
I need to figure out what is the standard/best practice for displaying localized UI text in an iOS from text that is received from a remote source, such as API driven, server-provided text. iOS Localization of static text is not a problem and we already have a system for managing that.
It seems to me the right and best thing would be to have the translated text sent by the server and displayed as received on the app, but there are some concerns about doing it this way, such as the app's locale/current language being possibly different than the current settings on the server. This presents the possibility that there may be a mismatch in dialect or language between what the phone is currently set to and what the server is set to. Also, we are considering how having the server do this breaks any of the S.O.L.I.D. design principles.
So, it comes to two possibilities. Either the server provides the translated text or the app does.
We could possibly provide a parameter to the server that would indicate which locale the device is set to (ie "en-us"). I imagine that this would be sent as an HTTP request header parameter.
It has also been suggested that the mobile app provide similar functionality for itself. This would involve maintaining a data store of some kind (tbd) so that display strings would be given to a facade and translated strings would be returned. ie: func translate(uiText: String) -> String. Internally, it could determine the user's locale and use that as part of the query needed to select the correct translated text. Again, the implementation of this would have to be decided, but that's not the problem I'm hoping to find a solution for.
To sum it up, what I really need is to know what is standard practice for translating server provided text that is to be displayed to the user and are there any frameworks out there designed to assist with this requirement (assuming the solution should exist in the mobile app)?
It seems to me that this is functionality best provided by the server. Also note that we have an Android app that would require similar enhancement.
I think I found a solution to this question but I do not want to mark it as the accepted answer unless I can get some feedback reinforcing what I have learned.
Most of the research I've done has lead me to what works for Web development, which is similar because it's still development but a much different creature than mobile. Mobile is compiled, which makes the advantages and disadvantages of where to do the presentation logic balance a little differently.
Some sources said it belongs on the server where it came from. Some sources said the client should do it. (I'll post references at the end.)
I opened up a discussion amongst my colleagues on the topic and this is where I found what I think will be our best solution. (Comments and criticisms are certainly welcome.)
I'll refer to data provided by the server through the API here forth as just "server".
For every string that the server provides that is meant to be displayed in the UI, I need to have some way to define these strings statically in the iOS app. Ideally I think an enum per display string would work. I can wrap every string with NSLocalizedString in the definition of the enum. Make the enum a String type, and initialize an instance of the enum from the string received from the server. The enum will return the NSLocalizedString. The iOS Localization system should export all of those localized strings, I will receive translations, and they will then exist in the various respective .strings files.
EG:
enum Emotion: String {
case happy = "Happy"
case sad = "Sad"
case angry = "Angry"
case joy = "Joy"
case amused = "Amused"
case bored = "Bored"
case undefined = ""
func translation() -> String {
switch self {
case .happy:
return NSLocalizedString("Happy", comment: "Happy")
case .sad:
return NSLocalizedString("Sad", comment: "Sad")
case .angry:
return NSLocalizedString("Angry", comment: "Angry")
case .joy:
return NSLocalizedString("Joy", comment: "Joy")
case .amused:
return NSLocalizedString("Amused", comment: "Amused")
case .bored:
return NSLocalizedString("Bored", comment: "Bored")
default:
return "--"
}
}
}
Implementation:
let thisCameFromTheServer: String? = "Happy"
let emo = Emotion(rawValue: thisCameFromTheServer ?? "") ?? .undefined
References
https://softwareengineering.stackexchange.com/questions/313726/where-should-i-do-localization-server-side-or-client-side
https://softwareengineering.stackexchange.com/questions/373395/api-internationalization
https://www.appliedis.com/localization-of-xcode-ios-apps-part-1/
What would be the best way to uniquely identify an MSConversation when developing an iMessages application?
In my case I want to give to a game object an ID of the conversation where it belongs to.
Take the localParticipant ID, add to it the remoteParticipants ID ;)
Something like that :
var conversationID = yourConversation.localParticipantIdentifier
for participant in yourConversation.remoteParticipantIdentifiers {
conversationID += participant
}
EDIT:
As noticed in comments, by doing so, you could end up with a very long ID. So the idea is to apply an hash to it, to have a constant size (MD5 is suffisant, we don't need something secure here). If it is still too long, you could crop that hash, but be aware that in that case there is a small probability for two conversations to have the same ID (depending on how much your crop).
The current top answer has a corruption issue in that if a new person is added to a group chat (or if someone is removed) your hashed ID will change.
A more elegant solution in my opinion is to just create your own serial number at the time of the first message being created and add it as meta-data to your message itself. (Using NSURLComponents of course). Then just grab that anytime a message is opened (thus launching your message app) and use that ID. Just keep it in the header of any message sent/received.
But, it depends on what you are trying to do really. The solution I've provided is great for turn-based multi-player games. It might not be good for other scenarios.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have two simple observables, for example,
val1 = ko.observable("input1");
val2 = ko.observable("input2");
and I want them to act like one, so when one of them changes, the other changes as well.
I know that in common case it's better to use only one observable and bind it to several dom elements. But in my case theese observables live in different templates and objects, so they can't be one variable.
Currently I subscribe one observable to another and vice versa:
val1.subscribe(function(v) {
val2(v);
});
val2.subscribe(function(v) {
val1(v);
});
However when you change the value of one observable, it updates the second, but that causes a ripple effect and updates the first one again, ad infinitum.
How can I set up a two-way binding between two separate observables which sets the value of one when you modify the other without causing an infinite loop?
You can do something like this:
vm1 = {
val1: ko.observable('input1'),
otherProperty: ko.observable('more')
}
vm2 = {
val2: vm.val1,
otherProperty: ko.observable('data')
}
Both vm1.val1 and vm2.val2 resolve to the same observable and therefore the same value.
Sethi's answer will work, but this might be better served with computed observables
Example: http://jsbin.com/exipuq/1/edit
var viewModelA = function(){
this.myVal = ko.observable();
};
var viewModelB = function(otherViewModel){
this.compVal = ko.computed(function(){
return otherViewModel.myVal();
});
};
// create a new viewmodel like normal
var vma = new viewModelA();
// pass the instantiated view model
// into the new one you're creating
var vmb = new viewModelB(vma);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
What is the need/purpose of converting an image to a byte array?
Why do we need to do this?
What's the purpose of converting an Image to a byte array?
Saving an image to disk
Serializing the image to send to a web service
Saving the image to a database
Serializing the image for processing
...are just a few that I can think of off the top of my head.
I think the most common use would be saving an image in a database (BINARY(MAX) data type).
Most common is to persist the image in the database as a blob (binary large object) but it could also be used in web services where you could take in a byte array as a method argument and then convert that to an image for whatever reason.
the only time i've ever needed to do this was to compare two images pixel-by-pixel to see if they were identical (as part of an automated test suite). converting to bytes and pinning the memory allowed me to use an unsafe block in C# to do a direct pointer-based comparison, which was orders of magnitude faster than GetPixel.
Recently I wrote a code to get hash from image, here is how:
private ImageConverter c = new ImageConverter();
private byte[] getBitmapHash(Bitmap hc) {
return md5.ComputeHash(c.ConvertTo(hc, typeof(byte[])) as byte[]);
}
Here is this in context. Serializing image or adding it to database in raw byte format (without mime type) is not something that seems to be sensible, but you can do that. Image processing and cryptography are most likely of places where this is useful.
To further generalize what Brad said: Serialization and (probably) a basis for object comparison.
Also is helpful if you have a image in memory and want to send it to someone via a protocol (HTTP for example). A perfect example would be the method "AddBytesForUpload" in the Chilkat HTTPRequest clas [http://www.chilkatsoft.com/refdoc/vbnetHttpRequestRef.html].
Why would you ever need to do this you may ask... Well lets assume we have a directory of images we want to auto upload to imageshack, but do some mods before hand like put our domain name at the bottom right. With this, u load the image in memory, do the mods with it that u need, then simply attach that stream to the HTTPRequest object. Without the array u would need to then same to a file before uploading, which in turn will create either a new file u then need to delete after, or over write the original, which is not always ideal.
public byte[] imageToByteArray(System.Drawing.Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}
If it is a image file use File.ReadAllBytes().