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.
Related
I am trying to check if AirPods are connected to the iPhone. How can I check it programmatically?
For airpods port.portType value is .builtInMic which is not sufficient to check if airpods are connected to iphone
class func isMicAvailbale() -> Bool{
let availableInputs:[AVAudioSessionPortDescription] = AVAudioSession.sharedInstance().availableInputs ?? []
var micPresent = false;
for port in availableInputs
{
if port.portType == .builtInMic{
micPresent = true
}
}
return micPresent
}
One way that comes to my mind is that you could use Core Bluetooth API to access the airpods via Bluetooth. But this might be overkill when you can use AVSession. I don't know why exactly you want to detect just airpods and no other bluetooth headphones. But I think buildInMic stands for buildIn microphone inside the device and not the bluetooth device :P If you take a look into docs you can see it :P
You didn't ask for other bluetooth headset, but as part of the answer I will provide you this code, this should work for non MFI headsets connected to iPhone via Bluetooth.
Now to the Airpod part.
You probably want to use ExternalAccessory.framework to communicate with the MFI bluetooth devices such as Airpods.~~
I haven't been working with EAAccessory yet but I believe you have to do something like this:
Create instance of EAAccessoryManager
Use that instance to get the connected devices
Find airpods via some ID
Figure out how to check if the accessory is connected, but this should be piece of cake.
Also very important step is to add UISupportedExternalAccessoryProtocols to your info.plist file
I am bit tired so if you have any questions ask, tommorow I will write the implementation in here if no-one will be faster.
Okay so obviously my answer was totally wrong on the first place.
I have learned today that Airpods aren't listed in apple's MFI devices so the ExternalAccessorymanager won't obviously work. As stated in the answer mentioned in the footer, all you need to do is to add category to the AVSession.
So the whole code is basically in here :D
let session = AVAudioSession.sharedInstance()
try! session.setCategory(.playAndRecord, mode: .default, options: .allowBluetooth)
guard let availableInputs = session.availableInputs else { return }
for input in availableInputs {
if input.portType == .bluetoothHFP {
// Do your stuff...
}
}
prove:
2019-01-04 02:32:13.462093+0100 Accessory games[24578:5411208] [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields: Unknown selected data source for Port Butcher’s AirPods (type: BluetoothHFP)
(lldb) po availableInputs
▿ 2 elements
- 0 : <AVAudioSessionPortDescription: 0x283b401b0, type = MicrophoneBuiltIn; name = iPhone Mikrofon; UID = Built-In Microphone; selectedDataSource = Vpředu>
- 1 : <AVAudioSessionPortDescription: 0x283b40250, type = BluetoothHFP; name = Butcher’s AirPods; UID = 10:94:BB:5D:5F:F7-tsco; selectedDataSource = (null)>
(lldb) po availableInputs[1].portName
"Butcher’s AirPods"
(lldb) po availableInputs[1].portType
▿ AVAudioSessionPort
- _rawValue : BluetoothHFP
(lldb)
Sorry for misunderstanding and writing totally offtopic answer. But hey, at least you know something about external accessories :)
Also you might want to take a look in here
I am trying to advertise a service with Multipeer Connectivity in macOS 10.13 as such:
override init() {
self.serviceAdvertiser = MCNearbyServiceAdvertiser(peer: peerID, discoveryInfo: nil, serviceType: serviceID);
super.init();
self.serviceAdvertiser.delegate = self;
self.serviceAdvertiser.startAdvertisingPeer();
}
where
private let serviceID = "sample-test";
private let peerID = MCPeerID(displayName: Host.current().localizedName!);
Instead of getting the proper delegate callback methods getting called the advertiser immediately fails and this is what I get in the console:
2017-10-16 11:22:35.568607-0700 macApp[3060:288948] [] tcp_listener_socket_create bind(fd 3) failed: [1] Operation not permitted
2017-10-16 11:22:35.569223-0700 macApp[3060:288940] [MCNearbyServiceAdvertiser] Server did not publish: errorDict [{
NSNetServicesErrorCode = 1;
NSNetServicesErrorDomain = 1;
}].
Any idea how to solve this?
UPDATE:
Running the exact same code in an iOS Simulator works fine so I'm guessing it has something to do with some permissions on the Mac machine.
Seeing that the log says that this is a permission issue I went ahead and enabled the root user on the Mac and tried running the same code to no avail.
I am thinking of turning off System Integrity Protection but I have a hard time coming to terms with the fact that Apple would publish this framework if all these security compromises are required in order to use it. Will keep investigating.
After days of struggle the solution is very simple. Make sure you enable the networking entitlements for your target. See attached snapshot:
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.
I've spent the whole day creating a system between my Mac and iPhone where i have used cocoaasyncsocket to create a listen server on my mac and a client on my iPhone. The basic idea is to leave the app on the mac running while the computer is on and then when I wish to transfer data from the iPhone app, fire up the app an it connects and sends the data... I have this system working exactly how I want it to function however I have 1 issue what I have been trying to solve for about 4 hours in total!
I wanted to create something what scans my wireless network for my mac with the listener running... I thought this would be simple, but I was wrong. I have searched high and low with no luck on the case and I am using stackoverflow as my last resort.
My current plan was to "autoscan" by retrieving the internal IP of the iPhone (ie 192.168.1.94) then use that to figure out what the other IP's on the network will be (192.168.1.0-254), now I know what IP's to scan i can loop through each one and check to see if the port is open/I get a response.
Now I want to do this as quick as possible however I haven't been able to get ANYTHING to give me accurate results...
Using connectToAddress:error: in the cocoaasyncsocket will simply just return true for every one of the 255 different IP addresses, so will any other reachability functions that I have come across... I have read that it is because they only check to see if the connection gets made and don't care about what happens at the other end so I need to think of something else.
My only other solution that I can think of, is to maybe ping each internal IP and see if i get a response but im not sure if this is going to take up too much time having to go through 255 IP addresses... and then, once i get what IP's are active I still then have to check to see if the port is open somehow :/
If anyone here knows how it can be done or has any better idea how I can check for the open port (i'm not very good with networking) I would be VERY grateful.
Thanks for reading,
Liam
Ok, I had a pay around today and I managed to get it working using Bonjour!
As it took me time to figure it all out I thought I will help anyone else out...
First off, on the listener side we need to set up a NSNetService, this can be done like so:
listenService = [[NSNetService alloc] initWithDomain:#"" type:#"_appname._tcp" name:#"Display Name" port:2427];
[listenService setDelegate:self]; //make sure you include the NSNetServiceDelegate
[listenService publish];
You can then plug into the NSNetServiceDelegate to make sure the service was published successfully and I used Bonjour Browser to check that my service was running fine (and it was)...
Then on the client we need to search for the service using [NSNetServiceBrowser][3]... This can be done like so:
serviceBrowser = [[NSNetServiceBrowser alloc] init];
[serviceBrowser setDelegate:self]; //remember to include NSNetServiceBrowserDelegate
[serviceBrowser searchForServicesOfType:#"_appname._tcp" inDomain:#""];
If you then include the NSNetServiceBrowserDelegate methods you can listen in to
netServiceBrowser:didFindService:moreComing:
You must then retain the service, give it a delegate and then resolve the service... Then if you listen into the NSNetServiceDeligate for the netServiceDidResolveAddress: you can then run the following code to convert the sockaddr into a readable IP address:
#include <arpa/inet.h>
-(void)netServiceDidResolveAddress:(NSNetService *)sender {
for (NSData* data in [sender addresses]) {
char addressBuffer[100];
struct sockaddr_in* socketAddress = (struct sockaddr_in*) [data bytes];
int sockFamily = socketAddress->sin_family;
if (sockFamily == AF_INET ) {//|| sockFamily == AF_INET6) { /*only support ipv4 atm*/
const char* addressStr = inet_ntop(sockFamily,
&(socketAddress->sin_addr), addressBuffer,
sizeof(addressBuffer));
int port = ntohs(socketAddress->sin_port);
if (addressStr && port) {
//you now have the services IP and Port.. all done
}
}
}
[sender release];}
Hope this helps anyone who is stuck with this.. Note that I borrowed parts of other samples/ instructions into one complete post what explains the whole system.
Enjoy.
I haven't worked with it myself but basically Bonjour is actually what you are looking for it's purpose is publishing and discovery of services
I've been playing with the background tasks and everything is fine (but bizzar), but now I try to do something like this:
protected override void OnInvoke(ScheduledTask task)
{
if (task is PeriodicTask)
{
ShellToast t = new ShellToast();
t.Content = "AAAAAAAAAAAAAAAAAAAAA";
t.Title = "mytitle";
t.NavigationUri = new Uri("/GotHereFromToastLink.xaml?someParam=" + 123, UriKind.Relative);
t.Show();
}
NotifyComplete();
}
Which SHOULD take me to GoHereFromToastLink.xaml when I press the toast notification, but instead it always takes me to MainPage.xaml - anybody knows if this is a bug? Or am I doing something incorrectly?
After contacting some really helpful MS guys I got a response - It's a known issue (aka bug) and it's already fixed but they don't have a date on the update to the Mango SDK but this will be working properly in the final release of the Mango toolset.
So for now - just ignore it.
I have the same problem!
Found out that the reason is the relative URI. I assume you have used another absolute URI in your application?