How to get status for bluetooth privacy setting in iOS6 - ios6

Question about iOS6 peripheral bluetooth connection.
in info.plist if I add UIBackgroundModes bluetooth-peripheral, at app launch it asks permission for first time.
"appname" would like to make data available to nearby bluetooth devices even when you're not using the app
if I deny (don't allow) the request, setting - privacy - Bluetooth Sharing - "Appname" turned to "OFF";
I set to listen CBPeripheralManagerDelegate to see if I can, but it always return "ON" even I deny the request. (that's also make sense because it is "on" before it goes to background)
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{
NSLog(#"%s",__func__);
NSLog(#"%#",[peripheral description]);
NSString *state = nil;
switch (peripheral.state) {
case CBPeripheralManagerStateResetting:
state = #"resetting"; break;
case CBPeripheralManagerStateUnsupported:
state = #"unsupported"; break;
case CBPeripheralManagerStateUnauthorized:
state = #"unauthorized"; break;
case CBPeripheralManagerStatePoweredOff:
state = #"off"; break;
case CBPeripheralManagerStatePoweredOn:
state = #"on"; break;
default:
state = #"unknown"; break;
}
NSLog(#"peripheralManagerDidUpdateState:%# to %# (%d)", peripheral, state, peripheral.state);
}
I see the CBPeripheralManagerStateUnauthorized looks like it shows denied status but I can't get this status even I denied request.
Question is:
"Is there any way I can find out user denied background access request?"

CBPeripheralManager has an authorizationStatus property which reports this information back. (Apple documentation link).
+ (CBPeripheralAuthorizationStatus)authorizationStatus
"Returns the app’s authorization status for sharing data while in the background state. A value indicating whether the app is authorized to share data using Bluetooth services while in the background. For a list of the possible values, see “Peripheral Manager Authorization Status.”"

Related

Trigger update on static browser property change

I'd like to trigger updates anytime the Notification.permission browser property changes. However, I'm not sure how to do this since Notification.permission is static.
The following never prints anything to the console, even if I change my browser's notifications permission:
function MyComponent() {
console.log(Notification.permission);
return <MoreGreatStuff />
}
There are diffrent option to check for permission
granted: The user has explicitly granted permission for the current origin to display system notifications.
denied: The user has explicitly denied permission for the current origin to display system notifications.
default: The user decision is unknown; in this case the application will act as if permission was denied.
You must check it like that,
(Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
Answered my own question with How to listen for web notification permission change
Permission state updates can be hooked via navigator.permissions.query
The gist:
const [permissionState, setPermissionState] = useState()
...
navigator.permissions
.query({ name: 'notifications' })
.then(permission => setPermissionState(permission.state)
Consumers of permissionState will be re-rendered any time it is updated.
This gives you a PermissionState rather than a NotificationPermission, but pish posh it accpmolishes the same thing

Is getting GPS data from mobile browser known to be somewhat flaky?

I currently have WORKING code where when user presses a button to share their location, the browser pops out a "Would you like to share your location?" and then the front end code handles the result. (HTML5 Geolocation API)
I have noticed that the failure rate is about 10%, by which I mean rate at which either position_unavailable triggers, or the unknown error in the code below:
$("#share-location-btn").click(shareLocation);
function shareLocation() {
$("#share-location-btn").prop("disabled", true);
$("#checking-location-msg").removeClass("hidden");
navigator.geolocation.getCurrentPosition(validateLocation, handleGeolocationError);
}
function handleGeolocationError(error) {
let errorText;
switch(error.code) {
case error.PERMISSION_DENIED:
errorText = "Location sharing was denied";
break;
case error.POSITION_UNAVAILABLE:
errorText = "Location can't be determined - contact us at XXX-XXX-XXXX";
break;
default:
errorText = "Unknown error - contact us at XXX-XXX-XXXX";
break;
}
errorUIHelper(errorText);
}
I'm trying to reduce the failure rate more. I feel like this must be possible, because services like bike sharing apps (e.g., Lime) literally require a GPS for every unlock action, and given how they do NOT have on-demand customer service for when this doesn't work, I'm assuming they have achieved a super low failure rate.
However, these services are of course apps. I understand that apps offer a lot more flexibility for geofencing services in general (e.g., location can be continually sent even when phone is locked, rather than requiring a user interaction).
That said, I kind of want to confirm, with people who are more experienced in doing geofencing on mobile browsers, NOT apps... is the mobile browser just known to be flaky? Because there are so many possible permutations of mobile device, operating system, browser, etc.?
And if this results in migration to an app, are apps also known to be generally less flaky in this regard?

Pidgin: cannot send messages or set topics in chats via dbus

I would like to send messages to Pidgin chats or set chat topics via dbus. Following this guide I was able to write some pretty straightforward code to do just that, and it does indeed result in messages appearing or chat topics being changed... but it only seems to affect my window, without the other participants being aware of any messages or topic changes.
I'm using
purple.PurpleConvChatSetTopic(chat_data, user, topic)
and
purple.PurpleConvChatWrite(chat_data, user, message, flag, time)
I don't think this is due to any misuse of the dbus api as the calls actually result in actions. I just wonder if I need to perform some sort of authentication first? Or maybe the user can only be the current user? I tried with my nick and also setting it as unicode but to no avail.
Here is the complete code anyway:
import dbus
import time
# define chat_name, user, topic, message
bus = dbus.SessionBus()
obj = bus.get_object('im.pidgin.purple.PurpleService', '/im/pidgin/purple/PurpleObject')
purple = dbus.Interface(obj, 'im.pidgin.purple.PurpleInterface')
for p in purple.PurpleGetConversations():
if purple.PurpleConversationGetName(p) == chat_name:
chat = p
chat_data = purple.PurpleConversationGetChatData(chat)
purple.PurpleConvChatSetTopic(chat_data, user, topic)
purple.PurpleConvChatWrite(chat_data, user, message, 0, int(time.time()))

PayPal SandBox PLATFORM error 589009

I am trying to get my IOS6 app to make payments to PayPal's sandbox but there seems to be some problem with the Beta release that I am using. I have included the PayPal-iOS-SDK-1.0.4 and have configured the environment to be PayPalEnvironmentSandbox and then I have added the credentials from my developer account as seen below:
if (payment.processable)
{
[PayPalPaymentViewController setEnvironment:self.environment];
NSString *customerId = [[[GlobalVariables sharedInstance] userAccount] objectForKey:#"email"];
PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc]
initWithClientId:kPayPalClientId
receiverEmail:kPayPalReceiverEmail
payerId:customerId
payment:payment
delegate:self];
paymentViewController.hideCreditCardButton = !self.acceptCreditCards;
[self presentViewController:paymentViewController animated:YES completion:nil];
}
The kPayPalClientId is the Client ID from the Rest API Credentials page and the kPayPalReceiverEmail is my PayPal account (which in this case is a Swedish account).
But when I run this against the Sandbox environment i just get PLATFORM error 589009.
But if I change the kPayPalReceiverEmail to a dummy one like: #"YOUR_PAYPAL_EMAIL#yourdomain.com" it works, but then the payment is no longer connected to my account (the amount seems to be drawn from my buyeraccount but no money ends up in my recieveraccount). So when I try to verify the payment it can't be done.
So what is the problem here you think?

CakePHP - Site Offline - Admin Routing Not Working

I setup the following code in my app_controllers.php file to control access to the site when the site is set to OFFLINE (site_status = 0).
function beforeFilter(){
// Site Offline = 0 , Site Online = 1
if($this->Configuration->get_site_status() == 1){
// Allow access to the site to all users and perform all required
// beforeFilter code
}else{
...
// If site is OFFLINE but User is logged in allow access.
// Later I will need to change it to only allow admin access if logged in as I am still developing
// Everyone else will be denied access even if they are able to authenticate
if(!$this->Auth->user() == null){
$this->layout = 'default';
$this->Auth->allow('*');
}else{
$this->layout = 'offline';
$this->Auth->deny('*');
}
...
}
}
Everything works great when the requested address looks like the following:
http://www.mydomain.com/articles
However, when I have the following it does not work properly
http://www.mydomain.com/admin/articles
It prevents access to the site correctly, but it fails to use the $this->layout = 'offline'. It defaults back to the default layout.
What do I need to do to fix this.
Thank you!
Your if conditions look weird. They are:
If site is offline and user logged in
use default layout
otherwise
use offline layout and require authentication on all pages
I.e. you're using offline layout when site is online OR user is not logged in. Are you sure that is what you want?
Well, the first thing that looks out of place to me is:
(!$this->Auth->user() == null)
This looks very wrong and might be causing your problems. I would suggest changing this to something like:
(!is_null($this->Auth->user())
or
($this->Auth->user() !== NULL)
Edits
First, check out the PHP logical operators. You were appending a NOT statement to the return value of $this->Auth->user(). So, with a user logged in you're essentially asking if false is equal to null, which of course it isn't and never will be.
Second, check out the PHP comparison operators. You aren't wanting to check if the value of $this->Auth->user() is equal to the value null, you're wanting to check if the data type of $this->Auth->user() is equal to the type null. In short, null is a data type, not a value. If you did just have to use "=" in your if statement then you would want to use the identical === check or the identical not check !==.

Resources