BlackBerry add new contact to address book - blackberry

the Blackberry app I'm working at requires me to export all app contacts to the BB address book. I'm able to retrieve the ContactList and create a new contact. However, when I call
AddressBookArguments entry =
new AddressBookArguments(AddressBookArguments.ARG_NEW, contact);
Invoke.invokeApplication(Invoke.APP_TYPE_ADDRESSBOOK, entry);
I'll have the new contact page of the address book poped up and have to manually press the save button. I can't let the user do this for all the contacts.
So my question is, is there a way to auto-save these newly created contacts?

You can certainly create new contacts programmatically.
Here is some sample code that creates a new contact with a company name and an email address. You can extend this with other fields, such as name, phone number, etc.
ContactList contactList = (ContactList)PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.WRITE_ONLY);
Contact newContact = contactList.createContact();
newContact.addString(Contact.ORG, Contact.STRING, "ACME Corporation");
if ( contactList.isSupportedField(Contact.EMAIL) )
{
newContact.addString(Contact.EMAIL, Contact.STRING, "johndoe#acme.com");
}
newContact.commit();

Related

Get data from unknown website using Webview

I'm currently creating an app where people can book online from a specific website. (The website is NOT owned by me) but is there any way I can get the user input from the website?
My idea is to let a user book from the webpage and their information like name, phone and last name will be saved into my app.
So if a user enter their first and last name on the webpage, I wanna retrieve the input as a string so I can later on create a notification when it's time to attend the booked event. Is there any way to do this?
webview.evaluateJavaScript("document.getElementById('first_3').value") { (data, err) in
if let err = err {
print(err.localizedDescription)
} else {
print("test", data)
}
}
I've added this one to the app, and I found the id "first_3" by viewing the elements.
So, how can I get the user input from a web view into my app?

Save email address to accounts app iOS

I have two apps (eg: App1 and App2) which requires login with an account. What I need to achieve is when an user log-in successfully into the App1, the email address should get saved to the default Accounts app of the device. Then when the user opens up the App2, the email address saved from App1 should show up as a recommendation for the user if he need to use the same account to sign in to App2 as well. Just like some apps do if you click on sign in with Google or Facebook.
Since I am new to iOS, I need to ask if this is possible to achieve in iOS and if yes what procedure should I follow.
EDIT
I tried implementing KeyChain for this. Something like below :-
void StoreKeysInKeychain (string key, string value) {
var s = new SecRecord (SecKind.GenericPassword) {
ValueData = NSData.FromString (value),
Generic = NSData.FromString (key)
};
var err = SecKeyChain.Add (s);
}
void GetRecordsFromKeychain (string key)
{
SecStatusCode res;
var rec = new SecRecord (SecKind.GenericPassword) {
Generic = NSData.FromString (key)
};
var match = SecKeyChain.QueryAsRecord (rec, out res);
if (match != null) {
// nsdata object : match.ValueData;
}
}
This way when I login to the App1 with an email address it gets saved and when I open the App2 I get that email address. This works fine. But now the issue is that if I logout from App1 and login with another email address. That account is not visible in App2. How can I get a list of all the email address?
Any help is appreciated.
you need to use app Group to share information among app, Enable app Group from build settings in both app and certificate , assign same group to them , and put information for each other on a suite of NSuserdefault .
Xamarin documentation for app group is here : https://developer.xamarin.com/guides/ios/watch/working-with/app-groups/
I believe you can set up a ParseServer that user account management for both apps

How to create contacts list like whats app did

I'm working on an app that creates an user profile. I need to be able to see who from my contacts has the app installed so that i am able to grant them access to my profile and see their profiles.
How do i get the full contact list, determine my phone number to create my account with it, and check how many people from the contacts have the app installed? (similar to how WhatsApp does it)
I know it's possible to get the contact list by using Apple API's, but do i have to send all the information to the server to check if they have the app installed?
Thank you.
I think you are managing one local database to store users locally.
First, You must have one contact mapping table on server that determines which number is allocate to which user (Each user must have unique number per account).
You have to pass array of phone numbers to your server request and fire query to get only those users whose phone numbers are in array.
You get one users objects array and that array you have to save in local database. (You can store all contacts in local database and update record (for appId, contactId, server name etc) is user is application user).
Finally these users who has appId are your application users.
Hope this concept might help you.
If you are using webservices your backend will can give the contacts which are using your application.
For getting the app contacts you have to use user phone number using phone number you can get the app user through webservices
to get all contact from Phonebook you can use below method in swift
first import Contacts
func FetchContact()
{
if #available(iOS 9.0, *) {
let contactStore = CNContactStore()
do {
let request:CNContactFetchRequest
request = CNContactFetchRequest(keysToFetch: [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactMiddleNameKey, CNContactEmailAddressesKey,CNContactPhoneNumbersKey])
request.sortOrder = CNContactSortOrder.GivenName
try contactStore.enumerateContactsWithFetchRequest(request) {
(contact, cursor) -> Void in
self.dataArray?.addObject(contact)
}
}
catch{
print("Handle the error please")
}
//self.collectionView?.reloadData()
}
}

Cloud code - "Execution timed out" during saveAll call in afterSave

Situation
I have a messaging Android app providing following feature(s)
to send message direct message to one selected recipient
to create public announcement that all users using the app receive (except author)
each user sees on his phone a list of messages he got
each message is either unread, read, or deleted
I use Parse.com as back-end
Current implementation
On Android client
When there is a new message, a new messageRequest of the MessageRequest class is created
If the message should be direct, the messageRequest has type 0, otherwise type 1
If the message is direct, there is recipient stored in the messageRequest object
The messageRequest object is stored to parse.com
On parse.com back-end
In the afterSave of the MessageRequest it is checked if the message is direct or public and based on that
in case of direct message - one new message object of the Message class is created and saved
in case of public announcement - for each user except author, a new message object is created and added to a list of messages, then the list is saved
In both cases, the data like content, type, etc. are copied from messageRequest object into the newly created message object(s).
The reason for creating separate message for each user is that each user can have it in another status (unread, read, deleted).
The status column representing the unread, read, deleted status is set (by unread) for the message object.
Problem
When I call the ParseObject.saveAll method in the afterSave of MessageRequest, I get the Execution timed out - Request timed out error
I think the cause is that there are some limits on time in which the request must complete
in cloud code. In my case, I'm creating ca 100 Messages for 1 MessageRequest
This doesn't seem so much to me, but maybe I'm wrong.
Source code
var generateAnnouncement = function(messageRequest, recipients) {
var messageList = [];
for (var i = 0; i < recipients.length; i++) {
var msg = new Message();
msg.set("type", 1);
msg.set("author", messageRequest.get("author"));
msg.set("content", messageRequest.get("content"));
msg.set("recipient", recipients[i]);
msg.set("status", 0)
messageList.push(msg);
}
Parse.Object.saveAll(messageList).then(function(list) {
}, function(error) {
console.error(error.message);
});
}
Parse.Cloud.afterSave("MessageRequest", function(request) {
var mr = request.object;
var type = mr.get("type");
if (type == 0) {
generateDirectMessage(mr);
} else {
var query = new Parse.Query(Parse.User);
query.notEqualTo("objectId", mr.get("author").id);
query.find().then(function(allUsersExceptAuthor) {
generateAnnouncement(mr, allUsersExceptAuthor);
}, function(error) {
console.error(error.message);
});
}
});
How would you suggest to solve this?
Additional thoughts
My only other idea how to solve this is to have only one Message object, and two columns called e.g. viewedBy and deletedFor which would contain lists of users that already viewed the message or have delete the message for them.
In this case, I'm not very sure about the performance of the queries
Also, I know, many of you think Why isn't he using table for splitting the M:N relation between the MessageRequest(which could be actually called Message in that case) and User?
My answer is that I had this solution, but it was harder to work with it in the Android code, more pointers, more includes in queries, etc.
Moreover, I would have to create the same amount of objects representing status for each user in the on parse.com back-end anyway, so I think the problem with Execution time out would be the same in the end
Update - mockup representing user's "Inbox"
In the "inbox" user sees both direct messages and public announcements. They are sorted by chronological order.
Update #2 - using arrays to identify who viewed and who marked as deleted
I have just one Message object, via type I identify if it is direct or public
Two array columns were added
viewedBy - containing users that already viewed the message
deletedFor - containing users that marked the message as deleted for them
Then my query for all messages not deleted by currently logged in user looks like this
//direct messages for me
ParseQuery<Message> queryDirect = ParseQuery.getQuery(Message.class);
queryDirect.whereEqualTo("type", 0);
queryDirect.whereEqualTo("recipient", ParseUser.getCurrentUser());
//public announcements
ParseQuery<Message> queryAnnouncements = ParseQuery.getQuery(Message.class);
queryAnnouncements.whereEqualTo("type", 1);
//I want both direct and public
List<ParseQuery<Message>> queries = new ArrayList<ParseQuery<Message>>();
queries.add(queryDirect);
queries.add(queryAnnouncements);
ParseQuery<Message> queryMessages = ParseQuery.or(queries);
//... but only those which I haven't deleted for myself
queryMessages.whereNotEqualTo("deletedFor", ParseUser.getCurrentUser());
//puting them in correct order
queryMessages.addDescendingOrder("createdAt");
//and attaching the author ParseUser object (to get e.g. his name or URL to photo)
queryMessages.include("author");
queryMessages.findInBackground(new FindCallback<Message>() {/*DO SOMETHING HERE*/});
I would suggest changing your schema to better support public messages.
You should have a single copy of the public message, as there's no changing the message itself.
You should then store just the status for each user if it is anything other than "unread". This would be another table.
When a MessageRequest comes in with type 1, create a new PublicMessage, don't create any status rows as everyone will use the default status of "unread". This makes your afterSave handler work cleanly as it is always creating just one new object, either a Message or a PublicMessage.
As each user reads the message or deletes it, create new PublicMessageStatus row for that user with the correct status.
When showing public messages to a user, you will do two queries:
Query for PublicMessage, probably with some date range
Query for PublicMessageStatus with a filter on user matching the current user and matchesQuery('publicMessage', publicMessageQuery) constraint using a clone of the first query
Client side you'll then need to combine the two to hide/remove those with status "deleted" and mark those with status "read" accordingly.
Update based on feedback
You could choose instead to use a single Message class for public/private messages, and a MessageStatus class to handle status.
Public vs Private would be based on the Message.recipient being empty or not.
To get all messages for the current user:
// JavaScript sample since you haven't specified a language
// assumes Underscore library available
var Message = Parse.Object.extend('Message');
var MessageStatus = Parse.Object.extend('MessageStatus');
var publicMessageQuery = new Parse.Query(Message);
publicMessageQuery.doesNotExist('recipient');
publicMessageQuery.notEqualTo('author', currentUser);
var privateMessageQuery = new Parse.Query(Message);
privateMessageQuery.equalTo('recipient', currentUser);
var messagesQuery = new Parse.Query.or(publicMessageQuery, privateMessageQuery);
messagesQuery.descending('createdAt');
// set any other filters to apply to both queries
var messages = [];
messageQuery.find().then(function(results) {
messages = _(results).map(function (message) {
return { message: message, status: 'unread', messageId: message.objectId };
});
var statusQuery = new Parse.Query(MessageStatus);
statusQuery.containedIn('message', results);
statusQuery.equalTo('user', currentUser);
// process status in order so last applies
statusQuery.ascending('createdAt');
return
}).then(function(results) {
_(results).each(function (messageStatus) {
var messageId = messageStatus.get('message').objectId;
_(messages).findWhere({ messageId: messageId }).status = messageStatus.get('status');
});
});
// optionally filter messages that are deleted
messages = _(messages).filter(function(message) { return message.status !== 'deleted'; });
// feed messages array to UI...

Get Blackberry Owner details (eg name/number) through API

I know this is a simple one, but I'm not sure the name of the framework item that will help me. (I know Google could solve this one but my keyworks fail me)
I'm trying to gather some of the BlackBerry owner's details (phone number, first/last name, edit: email address) to autofill a "Create new account" screen.
I'm using DeviceInfo to return the DeviceId, but unsure how to retrieve owner contact details.
To get the phone number:
String phoneNum = net.rim.blackberry.api.phone.Phone.getDevicePhoneNumber(false);
To get the Owner's name:
String owner = net.rim.device.api.system.OwnerInfo.getOwnerName();

Resources