Well this is the code snippet and works fine for me:-
Code:
TInt currentIAPId;
RConnection connection;
RSocketServ socketServ;
//Connect to the Socket Server and open a connection
User::LeaveIfError(socketServ.Connect());
User::LeaveIfError(connection.Open(socketServ));
TUint connectionCount;
//Enumerate currently active connections across all socket servers
User::LeaveIfError(connection.EnumerateConnections(connectionCount));
if (connectionCount)
{
TPckgBuf<TConnectionInfoV2> connectionInfo;
for (TUint count = 1; count <= connectionCount; ++count)
{
connection.GetConnectionInfo(count, connectionInfo);
// Check for the GPRS/Generic connection type
if(connectionInfo().ConnectionType() == EConnectionGPRS || connectionInfo().ConnectionType() == EConnectionGeneric)
{
// Check if bearer type is GPRS. If it is GPRS, then return IAP Id. Else check for next connection
TInt bearerType = GetBearerType(connectionInfo().iIapId);
if(bearerType == EApBearerTypeGPRS)
{
currentIAPId = connectionInfo().iIapId;
break;
}
}
}
}
// Cleanup and close resource handles
connection.Close();
socketServ.Close();
TApBearerType CDataPublisher::GetBearerType(TUint aIapId)
{
TInt wapId;
TApBearerType bearerType;
// Opens Comms database
CCommsDatabase *db = CCommsDatabase::NewL();
CleanupStack::PushL(db); //cs = 1
// Start transaction
User::LeaveIfError(db->BeginTransaction());
CApDataHandler* apDataHandler = CApDataHandler::NewLC(*db); // cs = 2
CApUtils *apUtils = CApUtils::NewLC(*db); //cs=3
// Get WAP Id from IAP Id
wapId = apUtils->WapIdFromIapIdL(aIapId);
CApAccessPointItem* wlanNew = CApAccessPointItem::NewLC(); // cs = 4
apDataHandler->AccessPointDataL(wapId,*wlanNew);
// Return the bearer type of the connection
bearerType = wlanNew->BearerTypeL();
User::LeaveIfError(db->CommitTransaction()); // // End a transaction. Call after `InsertRecord()` or `UpdateRecord()`.
CleanupStack::PopAndDestroy(4); // cs = 0
return bearerType;
}
I am checking for the bearer type on GPRS, you can change it according to your requirements. Once I get the IAP id, I call SetConsumerIapIdL(currentIAPId). Otherwise the first time the selection dialog is popped up and the connection is established and I get notified in SetStatus(implemented in my class-> comes from MSenServiceConsumer), case KSenConnectionStatusReady, I call the function to store the current active iap id.
Hope this helps..
Cheers,
Mayank