How can I get the CBUUID from the device that my app is currently running on? I'm using Xamarin but answer in objective-c or swift would be good too.
use Plugin.BLE (https://www.nuget.org/packages/Plugin.BLE/)
foreach(AdvertisementRecord record in e.Device.AdvertisementRecords)
{
if (record.Type == AdvertisementRecordType.UuidsComplete128Bit || record.Type == AdvertisementRecordType.UuidsComplete16Bit)
{
b.ServiceUUID = record.Data;
break;
}
}
Then
foreach(Beacon beacon in beaconList)
{
cbuuidList.Add(CBUUID.FromBytes(beacon.ServiceUUID));
}
CBUUID[] uuid = cbuuidList.ToArray();
BLEManager.ScanForPeripherals(uuid);
detail here: https://forums.xamarin.com/discussion/92838/proper-way-to-retrieve-uuid-of-device
Related
My project is Xamarin Forms in iOS device, and that using WIFI to work with other devices. I want to know whether it is possible to know the current connected ssid name first. If my app loses the link, can it silently try to reconnect to the WiFi without the user having to do anything?
Here is my logic diagram
You could use DependencyService to get a SSID name, you could refer to Xamarin.Forms DependencyService
In your service, try some code like this:
string ssid = "";
string[] supportedInterfaces;
StatusCode status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces);
if ((status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces)) == StatusCode.OK)
{
foreach (var item in supportedInterfaces)
{
NSDictionary info;
status = CaptiveNetwork.TryCopyCurrentNetworkInfo(item, out info);
if (status == StatusCode.OK)
{
ssid = info[CaptiveNetwork.NetworkInfoKeySSID].ToString();
}
}
}
In your info.plist, you should add this key:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your Description</string>
Once you get the SSID name (and password), you could use NEHostspotConfiguration to make a connection.
NEHotspotConfiguration hotspotConfiguration = new NEHotspotConfiguration(ssid,pwd,false);
hotspotConfiguration.JoinOnce = true;
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(hotspotConfiguration, (NSError error) =>
{
if (error != null)
{
if (error?.LocalizedDescription == "already associated.")
{
IsConnected = true;
}
else
{
IsConnected = false;
}
}
else
{
IsConnected = true;
}
});
You may also enable Access WiFi information, Hotspot capability of you App ID at the Apple Developer Portal and add them in your Entitlements.plist. Don't forget to regenerate your provisioning file. Hope my answer could help you~
I try to implement Mixpanel's tweaks into my app for A/B testing. This is my code:
if (MPTweakValue(kFeaturedOffersTweak, NO)) {
return MenuItemRowHeight;
}
else {
return 0;
}
On the first lunch everything is OK and tweak value is YES. Then I switch off internet on my iPhone, open run again and tweak value is NO.
What is correct way to use Mixpanel's tweak without internet?
So, I created my custom manager, where I implemented tweaks' persistency.
Please, let me know, if you have better solution.
My code:
-(void)initManager {
[[Mixpanel sharedInstance] joinExperimentsWithCallback:^{
USE_SETTINGS;
SETTINGS_SETBOOL(kPreferredPartnersTweak, MPTweakValue(kPreferredPartnersTweak, NO));
SYNCHRONIZE_SETTINGS;
//===
SEND_NOTIF(kTweaksUpdated, nil);
}];
}
-(BOOL)getTweakWithName:(NSString*)tweakName {
BOOL result = NO;
//===
USE_SETTINGS;
if (SETTINGS_BOOL(tweakName)) {
result = SETTINGS_BOOL(tweakName);
}
else {
result = MPTweakValue(kPreferredPartnersTweak, NO);
}
//===
return result;
}
USE_SETTINGS, SETTINGS_BOOL, SYNCHRONIZE_SETTINGS is my macros wrappers for working with NSUserDefaults.
Im trying to develop a blackberry native app, whose function is to lock the device. Is it possible to set the device lock state? should i use any third party api?
I found this java code..
ApplicationManager appman = ApplicationManager.getApplicationManager();
appman.lockSystem(true);
Anything similar in c++?
No. Is not possible with the current API.
You should use some trick such as show a dialog window or other.
You can do is understand the state of the device using the code below.
if (myHomeScreen.lockState == DeviceLockState.Unknown) {
console.log("No idea");
} else if (myHomeScreen.lockState == DeviceLockState.Unlocked) {
console.log("Unlocked");
} else if (myHomeScreen.lockState == DeviceLockState.ScreenLocked) {
console.log("Screen locked");
} else if (myHomeScreen.lockState == DeviceLockState.PasswordLocked) {
console.log("Password locked");
} else if (myHomeScreen.lockState == DeviceLockState.PinBlocked) {
console.log("PIN blocked");
}
This is an extract of this documentation.
When implementing the CBPeripheralManagerDelegate method -peripheralManager:willRestoreState, the object in the dictionary passed to the method for key CBPeripheralManagerRestoredStateServicesKey Apple's documentation states that
All the information about a service is restored, including any included services, characteristics, characteristic descriptors, and subscribed centrals.
From the array of CBMutableServicesthat are returned I can loop through the services and in turn loop through each service's characteristics. However I cannot figure out how to access the subscribed centrals, can anyone help?
Below is the general code I've used which assigns values to local variables etc:
- (void)peripheralManager:(CBPeripheralManager *)peripheral willRestoreState:(NSDictionary *)dict
{
advertisementData = dict[CBPeripheralManagerRestoredStateAdvertisementDataKey];
NSArray *services = dict[CBPeripheralManagerRestoredStateServicesKey];
for (CBMutableService *service in services) {
mainService = service;
for (CBMutableCharacteristic *charactristic in mainService.characteristics) {
if ([charactristic.UUID.UUIDString isEqualToString:AUTH_UUID]) {
authCharacteristic = charactristic;
} else if ([charactristic.UUID.UUIDString isEqualToString:CENTRAL_NAME_UUID]) {
receiveDeviceNameCharacteristic = charactristic;
}
}
// How would I reinstantiate subscribed centrals?
// subscribedCentrals = ?
[manager addService:mainService];
}
}
You can retrieve the subscribed centrals from the CBMutableCharacteristic objects -
so, something like -
NSMutableSet *centrals=[NSMutableSet new];
for (CBMutableCharacteristic *charactristic in mainService.characteristics) {
if ([charactristic.UUID.UUIDString isEqualToString:AUTH_UUID]) {
authCharacteristic = charactristic;
} else if ([charactristic.UUID.UUIDString isEqualToString:CENTRAL_NAME_UUID]) {
receiveDeviceNameCharacteristic = charactristic;
}
for (CBCentral *central in characteristic.subscribedCentrals) {
[centrals addObject:central];
}
}
I'd like my user to take a picture as an attachment by using the built in camera.
Is there someway to invoke the camera on a button press and save the resulting taken picture?
The other option is to use the BlackBerry Invoke API to start the native camera application and listen for a file system event:
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
then, later:
class FileExplorerDemoJournalListener implements FileSystemJournalListener {
public void fileJournalChanged() {
long nextUSN = FileSystemJournal.getNextUSN();
for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) {
FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
if (entry == null) {
break;
}
String path = entry.getPath();
if (path != null) {
if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){
switch (entry.getEvent()) {
case FileSystemJournalEntry.FILE_ADDED:
//either a picture was taken or a picture was added to the BlackBerry device
break;
case FileSystemJournalEntry.FILE_DELETED:
//a picture was removed from the BlackBerry device;
break;
}
}
}
}
}
}
Finally...
Application.addFileSystemJournalListener(new FileExplorerDemoJournalListener());
This will get you most of the way there... taken from: http://docs.blackberry.com/en/developers/deliverables/11942/Detect_when_img_is_added_or_removed_file_system_740288_11.jsp
http://docs.blackberry.com/en/developers/deliverables/17968/Take_a_picture_in_a_BB_device_app_1228201_11.jsp