Im using XMPPframework to create a chat for iphone. Im trying to connect the user to a certain chat room, but I can't do it.
This is the code I have:
BOOL activado = [salaChat activate:[[self appDelegate] xmppStream]];
[salaChat joinRoom];
[salaChat sendMessage:#"HELLO"];
BOOL unido = [salaChat isJoined];
Being salaChat a XMMPPRoom object.
"activado" is always true but "unido" never.
test_android is the username and "retiro" is the room id. Maybe the mistake is there but I tried many ways and still nothing.
Any ideas?
Thanks.
see http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-xmpp-integration/
Ok, solved it, I was putting wrong the name of the room.
It should be "roomid#conference.127.0.0.1" and nickname , the users nickname.
Related
I am building a mobile application where my users can connect using accounts-facebook.
What I would like to do is refreshing their list of friends that use the app when they are logging in (is this a good way to keep this list up to date ?) or when they are connecting
I built something like this :
Meteor.startup(function(){
myFunctionToRefreshFriendLists()
});
Meteor.onConnection(function(conn) {
if (this.userId) {
myFunctionToRefreshFrindLists();
}
}
But this returns me "undefined", even when the user is connected. I know there is a problem using "this.userId" (this here does not seem relevant to me) but I do not know what to do ?
Any help appreciated, thank you !
Don't use Meteor.onConnection, as it will run every time a user starts a new connection. This can happen frequently depending on the stability of their connection; instead use Accounts.onLogin:
Accounts.onLogin(function(user){
console.log(user.user._id)
});
http://docs.meteor.com/#/full/accounts_onlogin
This bug has been busting me for the past 4 hours.
Also when I swap it round and get the User data first then Message data... the User.name will show, but the Message.message will not. So the data is definitely going in but the relationship between them seems to be broken.
Firstly, +1 for the effort with the image you created to illustrate your problem.
The cause of your issue is that you never assigned the user to the message (or vice-versa).
Try
message.fetchUser = user;
or
user.fetchMessage = message;
Then save your context and perform the fetch request.
As Rog said, I needed to assign the user to the message (or vice vera). Basically I placed this bit of code after where its entering the data.
messageDetails.fetchUser = userDetails
I have looked at the sample code and still not able to figure out some key functionality of the framework without more in depth documentation. Normally there are books about frameworks but it seems like with this framework, you're on your own until it picks up more mainstream usage.
How do I get the roster list? I see that XMPPRosterCoreDataStorage has an NSMutableSet of rosterPopulationSet. Is this the set of XMPPUserCoreDataStorageObjects, i.e., users, that make up a roster?
My way I'm guessing is a hack--get the presence of every user as it's announced, and stash it in an array. Those are the online buddies. Somehow get the entire roster list, and everyone who is not online, is offline.
I figure that there should be an array of XMPPUserCoreDataStorageObjects, i.e., 30 contacts, 30 entries in the XMPPUserCoreDataStorageObjects table?
How would I access this array and how would I tell if they are online or not?
For online status, am I supposed to query something else, b/c it's not encapsulated in XMPPUserCoreDataStorageObjects is it?
I suppose I could use the didReceivePresence or similar methods, but all in all, I want to use the framework and not fight against it.
Appreciate it!
Thanks
Use XMPPRoster extension with either XMPPRosterCoreDataStorage or XMPPRosterMemoryStorage
Take a look at following code. Please note that this is not complete code but should give you an idea.
XMPPRosterMemoryStorage *rosterstorage = [[XMPPRosterMemoryStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:rosterstorage];
[xmppRoster activate:xmppStream];
[xmppRoster fetchRoster];
I try to create a service with:
LocalDevice localDevice = LocalDevice.getLocalDevice();
localDevice.setDiscoverable(DiscoveryAgent.GIAC);
String url = "btl2cap://localhost:"+uuid.toString()+";name="+name+";authorize=true;authenticate=true;encrypt=true";
L2CAPConnectionNotifier notifier = (L2CAPConnectionNotifier)Connector.open(url);
ServiceRecord = localDevice.getRecord(notifier);
// Set some attributes
// ...
conn = notifier.acceptAndOpen();
//...
I run this code on a Nokia 5800 and Nokia 2760, with 5800 I can see 2760, but not vice versa, I don't know what is the problem, I have think security problems...
Any ideas?
Thanks!
The problem was in the search, the device threw a BluetoothStateException giving "Busy". The solution I have found is introducing a delay between deviceSearch and serviceSearch.
So I'm stumped on this one.
In Mac OS X there is an easy way to get the "Me" card (the owner of the Mac/account) from the built-in address book API.
Has anyone found a way to find out which contact (if it exists) belongs to the owner of the iPhone?
You could use the undocumented user default:
[[NSUserDefaults standardUserDefaults] objectForKey:#"SBFormattedPhoneNumber"];
and then search the address book for the card with that phone number.
Keep in mind that since the User Default is undocumented, Apple could change at any time and you may have trouble getting into the App Store.
Another approach you could take, although it is much more fragile, is to look at the device name. If the user hasn't changed it from the default "User Name's iPhone" AND they are using their real name as an iPhone, you could grab the user name from that. Again, not the best solution by any means, but it does give you something else to try.
The generally accepted answer to this question is to file a Radar with Apple for this feature and to prompt users to choose their card.
Contacts container have a me identifier property on iOS that can be accessed using container.value(forKey: "meIdentifier")
if let containers = try? CNContactStore().containers(matching: nil) {
containers.forEach { container in
if let meIdentifier = container.value(forKey: "meIdentifier") as? String {
print("Contacts:", "meIdentifier", meIdentifier)
}
}
The identifier is a legacy identifier used in the old AddressBook framework. You can still access it in CNContact:
let iOSLegacyIdentifier = contact.value(forKey: "iOSLegacyIdentifier")
There is no such API in the iPhone SDK 2.2.1 and earlier. Please file a request for it at: http://bugreport.apple.com
Edit: [Obsolete answer]
There's no API for getting the "me" card because there is no "me" card. The iPhone's contacts app has no way of marking a card as being "me", and the API reflects this.
I came up with a partial solution to this
you can get the device name as follows
NSString *ownerName = [[UIDevice currentDevice] name];
in English a device is originally called, for example, 'Joe Blogg's iPhone'
the break out the name
NSRange t = [ownerName rangeOfString:#"’s"];
if (t.location != NSNotFound) {
ownerName = [ownerName substringToIndex:t.location];
}
you can then take that name and search the contacts
CNContactStore *contactStore = [CNContactStore new];
NSPredicate *usersNamePredicate = [CNContact predicateForContactsMatchingName:usersName];
NSArray * keysToFetch = #[[CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName],CNContactPhoneNumbersKey,CNContactEmailAddressesKey,CNContactSocialProfilesKey, ];
NSArray * matchingContacts = [contactStore unifiedContactsMatchingPredicate:usersNamePredicate keysToFetch:keysToFetch error:nil];
Of course other languages differ in the device name string e.g. 'iPhone Von Johann Schmidt' so more parsing needs to be done for other languages and it only works if the user hasn't changed the name of the device in iTunes to something like "Joes phone' but it gives you a starting point
well... it gives you an array of matching items :) So if there is more than one contact with that array you just have to use pot luck and go with the first one or work thru multiple cards and take what you need from each.
I did say its a partial solution and even though it won't work for all user cases you might find it works for many of your users and reduces a little friction