siphon calling doesn't work - pjsip - ios

So I have a compiled and running Siphon app but it just won't make the calls.
I get:
registration error - default error message.
Full error is this:
15:04:02.032 pjsua_call.c Making call with acc #0 to sip:6476805821#voip5-2.acanac.com
15:04:02.032 pjsua_call.c .Unable to make call because account is not valid: Invalid operation (PJ_EINVALIDOP) [status=70013]
15:04:05.580 call.m Error making call: Invalid operation (PJ_EINVALIDOP) [status=70013]
But when I use the same account on a different SIP app, it works perfectly fine.
When pjsip calls sip_dial_with_uri(_sip_acc_id, [url UTF8String], &call_id);
_sip_acc_id is 0 since I believe it's the 0th account that's in the settings for siphon.
url is the correct phone number I'm trying to dial but shows something like:
sip:62304892#url.com
and call id is just a reference so I dunno if it's important.
When I look at other voip apps, they have a registration process. Where you enter you username, password, and sip server domain or ip.
For Siphon, this is done in the settings file. However, if "register or login" is done in Siphon's code or not, I'm not sure.
Could that be the problem?
This is the code that tries to make an actual call:
/** FIXME plutôt à mettre dans l'objet qui gère les appels **/
-(void) dialup:(NSString *)phoneNumber number:(BOOL)isNumber
{
pjsua_call_id call_id;
pj_status_t status;
NSString *number;
UInt32 hasMicro, size;
// Verify if microphone is available (perhaps we should verify in another place ?)
size = sizeof(hasMicro);
AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable,
&size, &hasMicro);
/*if (!hasMicro)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"No Microphone Available", #"SiphonApp")
message:NSLocalizedString(#"Connect a microphone to phone", #"SiphonApp")
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", #"SiphonApp")
otherButtonTitles:nil];
[alert show];
[alert release];
return;
}*/
if (isNumber)
number = [self normalizePhoneNumber:phoneNumber];
else
number = phoneNumber;
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"removeIntlPrefix"])
{
number = [number stringByReplacingOccurrencesOfString:#"+"
withString:#""
options:0
range:NSMakeRange(0,1)];
}
else
{
NSString *prefix = [[NSUserDefaults standardUserDefaults] stringForKey:
#"intlPrefix"];
if ([prefix length] > 0)
{
number = [number stringByReplacingOccurrencesOfString:#"+"
withString:prefix
options:0
range:NSMakeRange(0,1)];
}
}
// Manage pause symbol
NSArray * array = [number componentsSeparatedByString:#","];
[callViewController setDtmfCmd:#""];
if ([array count] > 1)
{
number = [array objectAtIndex:0];
[callViewController setDtmfCmd:[array objectAtIndex:1]];
}
if (!isConnected && [self wakeUpNetwork] == NO)
{
_phoneNumber = [[NSString stringWithString: number] retain];
if (isIpod)
{
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:nil
message:NSLocalizedString(#"You must enable Wi-Fi or SIP account to place a call.",#"SiphonApp")
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK",#"SiphonApp")
otherButtonTitles:nil] autorelease];
[alertView show];
}
else
{
UIActionSheet *actionSheet = [[[UIActionSheet alloc] initWithTitle:NSLocalizedString(#"The SIP server is unreachable!",#"SiphonApp")
delegate:self
cancelButtonTitle:NSLocalizedString(#"Cancel",#"SiphonApp")
destructiveButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"Cellular call",#"SiphonApp"),
nil] autorelease];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView: self.window];
}
return;
}
if ([self sipConnect])
{
NSRange range = [number rangeOfString:#"#"];
NSLog(#"%i", _sip_acc_id);
if (range.location != NSNotFound)
{
status = sip_dial_with_uri(_sip_acc_id, [[NSString stringWithFormat:#"sip:%#", number] UTF8String], &call_id);
}
else
status = sip_dial(_sip_acc_id, [number UTF8String], &call_id);
if (status != PJ_SUCCESS)
{
// FIXME
//[self displayStatus:status withTitle:nil];
const pj_str_t *str = pjsip_get_status_text(status);
NSString *msg = [[NSString alloc]
initWithBytes:str->ptr
length:str->slen
encoding:[NSString defaultCStringEncoding]];
[self displayError:msg withTitle:#"registration error"];
}
}
}
Also if anyone has a link to the Siphon app's code that's newer and maybe works better, I'd appreciate that as well.
More info:
in call.m file essentially this gets called:
status = pjsua_call_make_call(acc_id, &pj_uri, 0, NULL, NULL, call_id);
and here
acc_id = 0
pj_uri = char *-> "sip:6476805821#voip5-2.acanac.com"
pj_ssize_t -> 33
call_id = 803203976

I figured this out. Turns out, the siphon app wasn't registering the account.
The code below is important:
pj_status_t sip_connect(pj_pool_t *pool, pjsua_acc_id *acc_id)
{
// ID
acc_cfg.id.ptr = (char*) pj_pool_alloc(/*app_config.*/pool, PJSIP_MAX_URL_SIZE);
if (contactname && strlen(contactname))
acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,
"\"%s\"<sip:%s#%s>", contactname, uname, server);
else
acc_cfg.id.slen = pj_ansi_snprintf(acc_cfg.id.ptr, PJSIP_MAX_URL_SIZE,
"sip:%s#%s", uname, server);
if ((status = pjsua_verify_sip_url(acc_cfg.id.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in local id argument",
acc_cfg.id));
[app displayParameterError: #"Invalid value for username or server."];
return status;
}
// Registrar
acc_cfg.reg_uri.ptr = (char*) pj_pool_alloc(/*app_config.*/pool,
PJSIP_MAX_URL_SIZE);
acc_cfg.reg_uri.slen = pj_ansi_snprintf(acc_cfg.reg_uri.ptr,
PJSIP_MAX_URL_SIZE, "sip:%s", server);
if ((status = pjsua_verify_sip_url(acc_cfg.reg_uri.ptr)) != 0)
{
PJ_LOG(1,(THIS_FILE, "Error: invalid SIP URL '%s' in registrar argument",
acc_cfg.reg_uri));
[app displayParameterError: #"Invalid value for server parameter."];
return status;
}
...
more code here
...
}
This is where your account gets registered to a SIP server.
Make sure the sip_connect function gets called from the main application itself shown below:
/* */
- (BOOL)sipConnect
{
pj_status_t status;
if (![self sipStartup])
return FALSE;
//if ([self wakeUpNetwork] == NO)
// return NO;
NSLog(#"%i", _sip_acc_id);
//if (_sip_acc_id == PJSUA_INVALID_ID)
//{
self.networkActivityIndicatorVisible = YES;
if ((status = sip_connect(_app_config.pool, &_sip_acc_id)) != PJ_SUCCESS)
{
self.networkActivityIndicatorVisible = NO;
return FALSE;
}
//}
return TRUE;
}
in my case _sip_acc_id wasn't equal to PJSUA_INVALID_ID therefore sip_connect was never getting called.
Thanks for all of those who tried to solve it in their head? :)

You are unlikely to get any useful help unless you post a code snippet as well as error output (at minimum). More context, such as configuration info and relevant aspects of your network, will further improve your chances.
(I would have added this as a comment on the question, but don't yet have the required reputation.)

Related

How to add contacts to openfire server using xmppFramework?

Hi I am making an chatting app for that i am using xmpp and openfire every thing working fine but when i add my contacts to openfire server first time it is not adding to server when i close my app and reopen then synchronize my contacts showing in openfire server i don't know where i miss
for adding to roster i just use this code
-(BOOL)addNewBuddyToMyAccount:(NSString *)buddyUserID withNickName:(NSString *)nickName{
NSString * buddyNameJID = [NSString stringWithFormat:#"%##mac-mini-2.local",buddyUserID];
XMPPJID *jid = [XMPPJID jidWithString:buddyNameJID];
[[self xmppRoster] acceptPresenceSubscriptionRequestFrom:jid andAddToRoster:YES];
[[self xmppRoster] addUser:jid withNickname:nickName];
return YES;
}
here i am adding my contacts
-(void)prepareForContactToAddAsRoster{
//getting user's contacts from contactlist
// Request authorization to Address Book
addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);
if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
// First time access has been granted, add the contact
if (granted) {
self.phoneContactArray=[self getAllContacts];
[self checkIfUserAllreadyOnXmppOrNotIfNotThenAddAsRoster:[self phoneContactArray]];
}
});
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
// The user has previously given access, add the contact
self.phoneContactArray=[self getAllContacts];
[self checkIfUserAllreadyOnXmppOrNotIfNotThenAddAsRoster:[self phoneContactArray]];
}
else {
[GMDCircleLoader hideFromView:self.view animated:YES];
// The user has previously denied access
// Send an alert telling user to change privacy setting in settings app
URBAlertView *alertView = [[URBAlertView alloc] initWithTitle:#"You denied access previously"
message:#"Please change privacy setting in settings app"
cancelButtonTitle:#"OK"
otherButtonTitles: nil, nil];
[alertView show];
}
}
above i am using address book for fetching contacts it is fetching first time only but not added to openfire server.
//here i am adding every contact to roster
for (int i=0; i<[tempContactList count]; i++) {
NSMutableString *tempNumber=[[[[[tempContactList objectAtIndex:i] numbers] objectAtIndex:0] stringByReplacingOccurrencesOfString:#"(" withString:#""] mutableCopy];
tempNumber=[[[[[[tempNumber stringByReplacingOccurrencesOfString:#")" withString:#""] mutableCopy] stringByReplacingOccurrencesOfString:#"-" withString:#""] mutableCopy] stringByReplacingOccurrencesOfString:#" " withString:#""] mutableCopy];
if (![dataBase checkJabberIDExistInDatabase:[NSString stringWithFormat:#"%##mac-mini-2.local",tempNumber]]) {
//not in xmpp server add as buddy
[[self appDelegate] addNewBuddyToMyAccount:tempNumber withNickName:[[tempContactList objectAtIndex:i] fullname]];
}
if any body familier then help me please

out of memory when reinstalling aplication

I'm desperate.
I create an application using sqlite an it was working fine until I submit an update to the apple store.
when my application is reinstalled and I tried to open a db connection I got an "out of memory" issue.
I've tried lots of stuff to solve this issue, but until today I was unable to solve this.
I use the code below to open db's connection:
-(Boolean)openConectionSQLiteDb
{
if (sqlite3_open([[GeneralFunction getInfoFromUserDefault:#"dbpath"] UTF8String], &db) != SQLITE_OK)
{
NSLog(#"Failed to open database!");
NSLog(#"%s",sqlite3_errmsg(statement));
//[GeneralFunction setDb:[[DbInteraction alloc] init:[GeneralFunction getDbName]]];
{
NSLog(#"Failed to open database! >>%#",[GeneralFunction getInfoFromUserDefault:#"dbpath"]);
// NSLog(#"222%s",sqlite3_errmsg(statement));
}
sqlite3_finalize(statement);
return false;
}
else
{
sqlite3_exec(db, "PRAGMA foreign_keys = on", NULL, NULL, NULL);
return true;
}
return false;
}
And the code below is used to insert date on the database:
-(Boolean)insertOrReplace:(NSDictionary *)elementoToInsert inTable:(NSString *)tableName
{
if([self openConectionSQLiteDb])
{
NSString * insert = [self createInsertStringWith:elementoToInsert in:tableName];
insert = [insert stringByReplacingOccurrencesOfString:#"INSERT" withString:#"INSERT OR REPLACE "];
const char *insert_stmt = [insert UTF8String];
sqlite3_prepare_v2(db, insert_stmt,
-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
sqlite3_finalize(statement);
sqlite3_close(db);
// NSLog(#"FECHOU");
return true;
}
NSLog(#"INSERT ERROR %s",sqlite3_errmsg(db));
sqlite3_finalize(statement);
}
sqlite3_close(db);
NSLog(#"FECHOU");
return false;
}
I'm also use this code to copy the Db file to a writable path when it necessary:
-(id)init:(NSString *) dbName
{
self = [super init];
nomeDb = dbName;
BOOL success;
NSFileManager *filemngr = [[NSFileManager alloc] init];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *writableDbPath = [documentDirectory stringByAppendingPathComponent:nomeDb];
// NSLog(#"%#",[GeneralFunction getInfoFromUserDefault:#"dbpath"]);
NSString * lastPath =[GeneralFunction getInfoFromUserDefault:#"dbpath"];
success = [filemngr fileExistsAtPath:lastPath];
if(!success)
{
NSLog(#"Arquivo não existe nesse Directorio >%#",lastPath);
success = [filemngr fileExistsAtPath:writableDbPath];
if(!success)
{
NSLog(#"Arquivo não existe nesse Directorio >%#",writableDbPath);
NSString *defaultDbPath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:nomeDb];
success = [filemngr copyItemAtPath:defaultDbPath toPath:writableDbPath error:&error];
NSLog(#"Copiou Para :%#",writableDbPath);
if (!success)
{
NSLog(#"Arquivo não existe nesse Directorio pela seguanda vez >%#",writableDbPath);
//[status setText:[error localizedDescription]];
/* UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];*/
}
else
{
NSLog(#"Achou 2");
NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
// NSLog(#"%#",writableDbPath);
[dic setObject:writableDbPath forKey:#"dbpath"];
[GeneralFunction saveTeacherInfo:dic];
writablePath = writableDbPath;
}
}
else
{
NSLog(#"Banco esta em %#",writableDbPath);
}
}
else{
NSLog(#"Achou");
}
// [bd executeUpdate:#"PRAGMA foreign_keys=ON"];
return self;
}
So when I install the application for the first time, it works fine. But if I run the applications again (It happens when I submit an update too) I got the LOG error "Failed to open database out of memory".
Someone please help me, I'm almost getting fired.
PS: I'm sorry for my terrible English. ;D
sqlite reports "out of memory" errors incorrectly at times. Usually if this occurs after an app update, it's because you have a bug in your sqlite access code. If your database schema has changed between app versions, but you didn't make sure that your database calls are backwards-compatible, you will frequently see this error.
If your CREATE TABLE statements aren't followed by ALTER TABLE statements to bring your schema up to speed when the CREATE fails because the table already exists, you run the risk of making database calls that are not backwards-compatible.
YEAH GUYS, finally I could solve my issue.
It was happening because when I was checking if there was a Database already copied in my writable path, in the TRUE condition I forgot to update my internal path that refers to the DB. For that reason when I was trying to open a connection, it was returning me the error because I was looking for the database in wrong place.

IP Camera Streaming on iPad stuck

I am getting stream on iPad from an IP camera named Foscam. If I open IP in iPad browser then it is working good but when I fetch stream in my application then it gets on frist screen shot and stuck on it. App is not getting continuous streaming from cam. I am using this way
- (IBAction)powerChanged:(id)sender {
UISwitch * s = (UISwitch *)sender;
if( s.on == TRUE){
[self initializeData];
if(![deviceClient connect]){
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Can not connect to T-Rex device!"
message:[[NSString alloc] initWithFormat:#"Could not connec to %# and %d port",deviceClient.host,deviceClient.port]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[message show];
[s setOn:FALSE animated:TRUE];
} else {
[self adjustLayout:TRUE];
[self startFrequencyTimer];
}
}else {
[self stopFrequencyTimer];
[self adjustLayout:FALSE];
}
}
-(void)initializeData {
[cameraViewFront loadRequest:[NSURLRequest requestWithURL:[frontCameraClient getVideoStreamURL]]];
}
-(BOOL)connect {
if (udpSocket == nil){
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
NSLog(#"host %# and port %i", self.host, self.port);
return [udpSocket connectToHost:self.host onPort:self.port error:nil];
}
- (NSURL *) getURL:(NSString *)forPage {
NSLog(#"front cam IP %#" ,self.host);
return [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:#"http://%#/%#user=%#&pwd=%#",self.host,forPage,self.username, self.password]];
}
-(NSURL *)getVideoStreamURL{
return [self getURL:#"videostream.cgi?"];
}
I figured it out. I am using foscam and foscam provides a list of URLs on this link so I searched my cam model and then tried all the given URLs for MPEG connection type and http://IPADDRESS/videostream.cgi?user=[USERNAME]&pwd=[PASSWORD]&resolution=32&rate=0 URL worked for my case. But still there is a problem that it is working awesome on iOS5 and on iOS6 it still stuck on first frame.
To fix this problem this link helped me a lot. This method works for iOS5 and 6 both.

iOS - twitter two-part post

I have my app filling out the tweet sheet for the user and sometimes it may go over 140 characters including the url. I am trying to develop a method which can split the tweet into two parts and post part 2 first, and then part 1 so it will look like:
(1/2) blah blah blah
(2/2) blah blah blah
Here is the method I have so far:
(void)sendTweet:(NSString *)msg setURL:(NSString*)url setImg:(UIImage*)img {
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// Set the initial tweet text. See the framework for additional properties that can be set.
if (![tweetViewController addURL:[NSURL URLWithString:url]])
NSLog(#"Unable to add the URL!");
if (![tweetViewController addImage:img])
NSLog(#"Unable to add the image!");
if (![tweetViewController setInitialText:msg])
NSLog(#"Unable to add the message!");
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
NSString *output;
switch (result) {
case TWTweetComposeViewControllerResultCancelled:
// The cancel button was tapped.
output = #"Tweet cancelled.";
break;
case TWTweetComposeViewControllerResultDone:
// The tweet was sent.
output = #"Tweet sent.";
break;
default:
break;
}
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:#"The Predictor"
message:output
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
// Dismiss the tweet composition view controller.
[self dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[self presentModalViewController:tweetViewController animated:YES];
}
Here is how i'm calling it, although the two part stuff isn't working...and I would like this functionality built-in to the method above.
if ([alertView tag] == 1) {
if (buttonIndex != [alertView cancelButtonIndex]) {
NSString *theURL = #"PredictorApps.com";
NSString *theTweet = [NSString stringWithFormat:#"%# - %#\n%#", [[Singleton sharedSingleton].spreadDate substringToIndex:5], theTitle, theMessage];
if (([theURL length] + [theTweet length]) <= 120)
[self sendTweet:theTweet setURL:theURL setImg:nil];
else if (([theURL length] + [theTweet length]) > 120) {
NSString *partTwo = [theTweet substringFromIndex:(([theURL length] + [theTweet length]) / 2)];
NSLog(#"Part Two: %#", partTwo);
[self sendTweet:partTwo setURL:theURL setImg:nil];
NSString *partOne = [theTweet substringToIndex:(([theURL length] + [theTweet length]) / 2)];
NSLog(#"Part One: %#", partOne);
[self sendTweet:partOne setURL:theURL setImg:nil];
}
}
}
any assistance is appreciated.
You have to use URL shorteners for reduce the URL size to post in twitter of facebook...For that you can refer to this link..This is a simple coding to shortening any type of URL u have..So u can reduce 2 part of post into single..I hope this will help you....
http://www.icodeblog.com/2010/02/04/iphone-coding-recipe-shortening-urls/
All the best....

Display a loading indicator after user taps "Share" and before request is completed?

The issue I have is that after users tap on the "Share" button of the FBDialog, they do not get any visual feedback until the request completes or fail... and over 3G that can takes a while. During this time users do not know if they tapped "Share" correctly or not, and there's risk of posting content twice.
Is there a way I can get a callback so I can display a loading indicator during this time? Where should I put this piece in?
Thank you!
Below code you write to fbAgent.m and also obser code here u get one "PID" at that time u write to alert msg ....... user can understand to that msg was success posted Facebook.
I hope this helps.
- (void)request:(FBRequest*)request didLoad:(id)result {
if ([request.method isEqualToString:#"facebook.fql.query"]) {
NSArray* users = result;
NSDictionary* user = [users objectAtIndex:0];
NSString* name = [user objectForKey:#"name"];
// Calling the delegate callback
[delegate facebookAgent:self didLoadName:name];
} else if ([request.method isEqualToString:#"facebook.users.setStatus"]) {
newStatus = nil;
NSString* success = result;
if ([success isEqualToString:#"1"]) {
// Calling the delegate callback
[delegate facebookAgent:self statusChanged:YES];
} else {
[delegate facebookAgent:self statusChanged:NO];
}
} else if ([request.method isEqualToString:#"facebook.photos.upload"]) {
NSDictionary* photoInfo = result;
NSString* pid = [photoInfo objectForKey:#"pid"];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:#"success Uploaded Your image please check your FaceBook", pid] delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alertView show];
[alertView release];
fbbut.enabled=YES;
[fbact stopAnimating];
self.uploadImageData = nil;
self.uploadImageCaption = nil;
self.uploadImageAlbum = nil;
//[delegate facebookAgent:self photoUploaded:pid];
if(newStatus){
[self setStatus:newStatus];
}
}
}
Start your indicator when you click on button and stop on Delegate of Facebook function
- (void)dialogDidComplete:(FBDialog *)dialog
Hope it helps....

Resources