How to get the identifier value from the broadcasting beacon? - ibeacon

Here my approach.
Broadcating beacon with UUID and identifier like this.
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:#"B57A1B68-48B7-4DBF-914C-760D08FBB87B"];
// Initialize the Beacon Region
self.myBeacon = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
major:1
minor:1
identifier:#"com.mycompany.xxx"];
And extracting beacon info like this
-(void)locationManager:(CLLocationManager*)manager
didRangeBeacons:(NSArray*)beacons
inRegion:(CLBeaconRegion*)region
{
CLBeacon *beacon = [beacons firstObject];
NSLog(#"becons details = %#",beacon);
}
And the result
becons details = CLBeacon (uuid:<__NSConcreteUUID 0x178038200> B57A1B68-48B7-4DBF-914C-760D08FBB87B, major:1, minor:1, proximity:1 +/- 0.11m, rssi:-40)
This how I get the major value
NSString *major = [NSString stringWithFormat:#"%#", foundBeacon.major];
Please anybody help me how to get the identifier value like "com.company.xxx" from the broadcasting beacon?
Thank you.

Unfortunately, you can't. Those identifiers are only helpful within the same application, but they don't actually get physically broadcasted in the bluetooth packets.
An alternative would be for the app to act as a peripheral and advertise services and characteristics which contain this company identifier value, but this approach is not as passive as iBeacons and would require a central to actively connect to the peripheral and read the characteristic values. It's not as hard as it sounds, but really depends on your use case.

Related

iOS 8 third party keyboard identification

How can I tell which third party keyboard the user is using or switching to?
I did not find any notification or API that I could use to check this info.
You can't know which keyboards are installed, nor can you decide which keyboard to load next.
Apple's documentation states:
To ask the system to switch to another keyboard, call the
advanceToNextInputMode method (..) The system picks the appropriate
“next” keyboard; there is no API to obtain a list of enabled keyboards
or for picking a particular keyboard to switch to.
For further information, read Apple's Custom Keyboards API Documentation:
https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html#//apple_ref/doc/uid/TP40014214-CH16-SW21
A bit late but you can get the list of active keyboards on a device. All keyboard identifiers are stored in UserDefaults and here is how you can get them:
/**
- Author:
Panayot Panayotov
- returns:
True or False
- Important:
Result is returned immediately after non system identifier is found
This method iterates through all public keyboard identifiers and
evaluates a regex that matches system keyboards
[
"nb_NO#sw=QWERTY-Norwegian;hw=Automatic",
"zh_Hant-Zhuyin#sw=Zhuyin;hw=Automatic",
"ur#sw=Urdu;hw=Automatic",
"zh_Hant-HWR#sw=HWR-Traditional",
"zh_Hant-Pinyin#sw=Pinyin10-Traditional;hw=Automatic",
"emoji#sw=Emoji"
]
*/
-(BOOL)hasUnkownKeyboard {
NSString * appleKeyboardsRegexp = #"^(?:[0-9a-zA-Z_\\-]+)(?:#sw|#hw)[0-9a-zA-Z_\\-\\-;=]*$";
NSPredicate * appleKeyboardsTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", appleKeyboardsRegexp];
NSArray *keyboards = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] objectForKey:#"AppleKeyboards"];
for (NSString *keyboard in keyboards) {
if(![appleKeyboardsTest evaluateWithObject:keyboard]){
return YES;
}
}
return NO;
}

Cocoa: User Notifications never being delivered

I'm trying to deliver a local notification, it looks something like this:
NSUserNotification *notification = [[NSUserNotification alloc] init];
//set title, subtitle, and sound
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
But the notification doesn't appear. I know sometimes notifications are not presented if the app is frontmost but at the time of delivery it's not. In system preferences I made sure that notifications from my app are allowed, and I even overrode the userNotificationCenter:shouldPresentNotification: method to always return YES but it still doesn't present the notification.
What is most confusing is that everything was working fine until I updated to Mavericks. I suppose something has changed in the update but I can't figure out what.
Thanks for the help.
my guess is that something is nil. make sure you are either assigning a (valid and non-nil) title, or informativeText.
I imagine that having invalid values for other properties such as otherButtonTitle might prevent the notification from being displayed as well.
Are there any error messages in your console?
Use the debugger or NSLog() statements to assess the values assigned to the notification. You could also see this problem if the NSUserNotification pointer is nil (not the case from the code you posted, but worth mentioning).
Here is a minimal test for an app delegate that works on Mac OS X 10.9 (Mavericks):
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSUserNotificationCenter* unc = [NSUserNotificationCenter defaultUserNotificationCenter];
unc.delegate = self;
NSUserNotification* notice = [[NSUserNotification alloc] init];
notice.title = #"title"; // notifications need a title, or informativeText at minimum to appear on screen
//notice.informativeText = #"informativeText";
NSLog(#"notification: %#, notification center:%#", notice, unc);
[unc deliverNotification:notice];
}
// The notifications will always dispaly even if we are in the foreground
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
return YES;
}

How can I get the current Macbook's UUID from Objective-C?

Does the SDK provide an API for retrieving the current Macbook's UUID?
So, if you don't care about the new AppStore rules etc... here you go:
- (NSString *)getSystemUUID {
io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault,IOServiceMatching("IOPlatformExpertDevice"));
if (!platformExpert)
return nil;
CFTypeRef serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert,CFSTR(kIOPlatformUUIDKey),kCFAllocatorDefault, 0);
if (!serialNumberAsCFString)
return nil;
IOObjectRelease(platformExpert);
return (__bridge NSString *)(serialNumberAsCFString);;
}
Please Note:
You need to add IOKit.framework to your project in order for this
to work.
This code is ARC compliant;
This code is safe and it will return a nil NSString if something goes wrong;
Apple does not guarantee that all future systems will have a software-readable serial number.
Developers should not make any assumptions about the
format of the serial number such as its length or what characters it
may contain.

Why is this contact always coming up as Nil / null, even when I set it or add emails?

In iOS 6, this code always gives me Nil for the second NSLog, however the first always gives the correct Composite Name. Hence I know I have access to the addressbook, if I change the name in addressbook, the code logs the correct Composite Name. No matter how many emails I put in, the contact ABMultiValueGetCount is always Nil. Why is this?
ABRecordRef person = (__bridge ABRecordRef)[addressBookArray objectAtIndex:x];
NSLog(#"%# -", ABRecordCopyCompositeName(person));
NSLog(#"%ld -", ABMultiValueGetCount(ABRecordCopyValue(person, kABPersonEmailProperty)));
Got it ... looks like some sort of managedObjectContext condition I should have anticipated ...
In one View Controller I did this:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
addressBookArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
// Prsented info on the user name, but not on the Emails
CFRelease(addressBook);
In the second view controller I passed addressBookArray to try and save on some cycles then did this:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
// Successfully accessed name properties (suspect they were chached some where ?
// Unsuccsfully accessed email properties (they have never been accessed so no chache and I get Null
CFRelease(addressBook);
The fix ... In the secondviewController repeat:
addressBookArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
Bingo problem solved !!
Please check following links. Those may solve your problem. In ios6 apple have changed the permission of address book.
App crashed in iOS 6 when user changes Contacts access permissions
iOS 6 Address Book not working?

Cocoa AsyncUDPSocket framework, (long)tag variable explanation and my delegate only sometimes called

my first post and also my first question. I am currently playing around with the Artnet protokoll, which is based on UDP. Trying to develop an Cocoa Application that reads Artnet data. I decided to use the AsyncUDPSocket Cocoa framework and got it working somehow.. So when i try to send a packet to my listen port using
nc -u localhost 6454
my delegate gets called. If i try this with another Artnet application my delegate never gets called back, but i can see the packets in the packet analyzer..
I suspect it must be something caused by the "tag". Can someone explain the (long)tag variable as i can find no Documentation about this Value and i can find no answer on the net. Also i might add i am relatively new to cocoa developing so maybe it´s a very basic error..
below is my init code for the sockets:
listenSocket_unicast = [[AsyncUdpSocket alloc] initWithDelegate:self]; // This one is not added to the Autorelease pool, so cocoa doesnt delete my socket object.
listenSocket_broadcast = [[AsyncUdpSocket alloc] initWithDelegate:self]; // This one is not added to the Autorelease pool, so cocoa doesnt delete my socket object.
// Bind unicast socket..if adress is not the loopback device
if (![SocketAddress isEqualToString:#LOOPBACK])
if ([listenSocket_unicast bindToAddress:SocketAddress port:ARTNET_PORT error:nil] == NO)
{
NSLog (#"Could not bind unicast socket on Adress %# and port %i",SocketAddress, ARTNET_PORT);
return NO;
}
else NSLog (#"Unicast Socket bind to on Adress %# and port %i",SocketAddress, ARTNET_PORT);
// Bind broadcast socket..
if ([listenSocket_broadcast bindToAddress:SocketBroadcastAdress port:ARTNET_PORT error:nil] == NO)
{
NSLog (#"Could not bind broadcast socket on Adress %# and port %i",SocketBroadcastAdress, ARTNET_PORT);
return NO;
}
else
NSLog (#"Broadcast Socket bind to on Adress %# and port %i",SocketBroadcastAdress, ARTNET_PORT);
[listenSocket_unicast receiveWithTimeout:-1 tag:0];
[listenSocket_broadcast receiveWithTimeout:-1 tag:0];
[listenSocket_broadcast enableBroadcast:YES error:nil];
and the code i currently try to get working:
-(BOOL)onUdpSocket:(AsyncUdpSocket *)sock didReceiveData:(NSData *)data withTag:(long)tag fromHost:(NSString *)host port:(UInt16)port
{
[sock receiveWithTimeout:-1 tag:0];
NSLog (#"UDP Delegate executed");
return YES;
}
Thanks in advance,
matthias
Glad you found your problem, but to actually answer your question about the tag variable, it's simply a way to track messages. The tag is not sent with the messages, but when a response comes to it, that will have the same tag, so you can organize them. If you don't need to do that sort of thing, just leave tag as 0 and you can ignore it.
The problem was i did not call the Read method at first.. so the reading never started.

Resources