Enumerate UISupportedExternalAccessoryProtocols at runtime - ios

I'm using Xamarin.iOS to wrap an Objective-C library for an accessory that connects to iPods and iPhones via the dock connector. I wasted a lot of time trying to get the accessory to work in my test app before I discovered that I was missing values under UISupportedExternalAccessoryProtocols in Info.plist in my test app.
I'd like to prevent others from running into the same problem when they use my wrapper library. Since this is a library, I can't have an Info.plist in my project, right? So I'd like to enumerate the values the caller has for UISupportedExternalAccessoryProtocols so I can give an easy to read message to developers that they're missing values. Is there a way to do this at run time?
Thanks!

Either of these will work to access values in the Info.plist:
var protocolArray = (NSArray)NSBundle.MainBundle.InfoDictionary ["UISupportedExternalAccessoryProtocols"];
Or
var protocolArray = (NSArray)NSBundle.MainBundle.ObjectForInfoDictionary ("UISupportedExternalAccessoryProtocols");
then get the values like so:
for (nuint i = 0; i < protocolArray.Count; i++) {
Console.Write (protocolArray.GetItem<NSString> (i).ToString ());
}

You can use
var values = NSBundle.MainBundle.ObjectForInfoDictionary("UISupportedExternalAccessoryProtocols");
to read the value from Info.plist and see if it contains all the required values.

Related

Changing Firebase configuration at runtime on iOS

For my project, I have 2 environments:
test
prod
and 2 localizations:
en
tr
and an app for each combination: (these names do not mirror Firebase project ids)
test_en
test_tr
prod_en
prod_tr
And I have a separate plist file for each of these apps in the project, with the names Firebase-(app_type).plist ie Firebase-test_en.plist or Firebase-prod_en.plist
I am initializing FIRApp using this way:
private func ensureLoaded() {
let options = FIROptions(contentsOfFile: Bundle.main
.path(forResource: "Firebase-\(firebaseApplicationName)", ofType: "plist"))!
if nil == FIRApp(named: firebaseApplicationName) {
FIRApp.configure(withName: firebaseApplicationName, options: options)
}
}
And it seems to work ok, until I try to actually connect to firebase database, where it says:
Firebase is not configured correctly, please call [FIRApp configure]
So my question is, how do I make firebase work where I want to dynamically change configurations? There are some other questions that describe how to change configuration based on some environment variables / compiler flags but they are all referring to changing the plist file, which changes the configuration during build time, but I want to change it dynamically during runtime. Is it supported at all, is there a way to make it work?
Thanks in advance.
I found what the problem was, we were using FIRApp.auth().currentUser somewhere in the app, which returns the auth for "default" app and since we had multiple configs, we had no notion of a "default" app, so the configuration was incomplete. I changed that to FIRAuth(app: myApp)?.currentUser and it works as expected now.

How to set path to picture in folder in device in android appcelerator app

So I have app where I want to let users to share screenshot of score to facebook etc... I'm using SocialShare widget. In documentation it says to set path to image like this: "image:fileToShare.nativePath", but I'm not really sure how to set it. Another problem is that I need to share picture that has always different name, it saves screenshots with names like tia7828157.png,tia107997596.png... in folder in device internal memory in pictures/enigmania/ I'm new to appcelerator, so I dont know if there is something like wildcard I could use for this? Thanks for any help.
This is my code so far which I know is wrong, I know the widget works because it shares text without problem:
function shareTextWidget(e){
// share text status
var socialWidget=Alloy.createWidget('com.alcoapps.socialshare');
socialWidget.share({status:"Enigmania kvíz",androidDialogTitle:"hoho",image:test.png/pictures/enigmania});
}
You should use Ti.Filesystem class methods/properties to get the path of any file located on internal or external storage.
Also aware of the permissions of reading storage on Android 6+. Use Storage Permissions before accessing any file on Android 6+.
Simple code snippet to create a directory on internal storage at this location: pictures/enigmania and then write an image file of captured view in this directory.
function shareTextWidget(e){
var directory = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'pictures/enigmania');
!directory.exists() && directory.createDirectory();
var fileToShare = Ti.Filesystem.getFile(directory.resolve(), 'screen.jpg');
fileToShare.write($.SCREENSHOT_VIEW.toImage()); // write the blob image to created file
var socialWidget=Alloy.createWidget('com.alcoapps.socialshare');
socialWidget.share({status:"Enigmania kvíz",androidDialogTitle:"hoho",image:fileToShare.nativePath});
}
This code should work without any issues.
Note that $.SCREENSHOT_VIEW is the View ID for which you will take screenshot, so it depends on you how you maintain your View positions in order to capture correct screenshot, but point is to use Ti.UI.View toImage() method to capture the screenshot of particular view.
Let me know if this works for you or not, else we can look into other methods by getting your exact requirements. Good Luck!!!!

How to use SpringboardServices to get notifications count of an app ios

How can I get notifications count of another app into my app by using SpringboardServices and SBSPushStore?
I'm trying to show notification count taken from whatsapp into my app so I was searching around and one thing is for sure that it is possible but I didn't find any approbate way on how to do it.Here is the question which answers it but I didn't get it. How to do it? Can someone please share the step by step procedure.
Based on the question I was able to find the code which can actually lock you iphone using SpringboardServices but I don't know how to use it for SBSPushStore?
void *SpringBoardServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
NSParameterAssert(SpringBoardServices);
mach_port_t (*SBSSpringBoardServerPort)() = dlsym(SpringBoardServices, "SBSSpringBoardServerPort");
NSParameterAssert(SBSSpringBoardServerPort);
SpringBoardServicesReturn (*SBSLockDevice)(mach_port_t port) = dlsym(SpringBoardServices, "SBSLockDevice");
NSParameterAssert(SBSLockDevice);
mach_port_t sbsMachPort = SBSSpringBoardServerPort();
SBSLockDevice(sbsMachPort);
dlclose(SpringBoardServices);
The answer to that linked question you commented on implies that you don't need any framework, as long as your device is jailbroken.
You simply load the plist file located at /var/mobile/Library/SpringBoard/applicationState.plist. The format of that answer is a bit broken, but I assume the > are meant as indicators to explain the inner structure of the file (i.e. key values).
So from that I assume it's a dictionary, you can load it by
NSDictionary *plistFile = [NSDictionary dictionaryWithContentsOfFile:#"/var/mobile/Library/SpringBoard/applicationState.plist"];
NSDictionary *entryForYourApp = plistFile[#"com.app.identifier"]; // obviously you have to use the identifier of whatever app you wanna check
NSInteger badgeCount = entryForYourApp[#"SBApplicationBadgeKey"];
You probably want to inspect the file yourself first (so set a debug point) and make sure its structure is like I assumed, the types are correct and so forth (not to mention it exists, Apple sometimes changes stuff like that and the other question is already several years old).
In general be aware that you can only do that, as said, on a jailbroken device. Otherwise your application simply doesn't have reading access to the path /var/mobile/Library/SpringBoard/applicationState.plist. Or to anything outside its sandbox, for that matter.

Get all options from Android Spinner using Appium

I am trying to pull all the options off an android spinner, using Appium. With Selenium, you can use the Select object and do something like getOptions (I forget the exact syntax). I need the text from all the options in the spinner.
Considering the spinner options are accessible through Appium. Getting all the values of the options on the spinner shall work as follows :
List<WebElement> spinnerList = driver.findElements(getBy("identifier")); //where identifier would vary on how you can access the elements
String spinnerListElementText[index]; //e.g. to store Text of all the options
for (int index = 0; index < spinnerList.size(); index++) {
String spinnerListElementText[index] = spinnerList.get(index).getText();
}
In Appium, there are test frameworks called Uiautomator, Uiautomator2 and Espresso, respectively. The thing that you were trying to get is not provided by Uiautomator or Uiautomator2 test frameworks. The only way with those frameworks is to click the spinner and get page source of spinner with visible elements. You could try to use Espresso framework. This is the reason:
Uiautomator: It is a test framework which provides a black-box testing for developers. It means that you can not get internal codes of the application.
Espresso: It is a test framework which provides a grey-box testing for developers. It means that you can get internal codes of the application, find elements which are not visible in the page (off-screen elements).
Try to use Espresso framework in Appium.

Using reopened standard file descriptors in an iOS app with background capabilities?

I would like to be able to redirect my logging statements to a file so that I can retrieve them when my app runs standalone (i.e. is not attached to Xcode). I have discovered (thank you Stackoverflow) that freopen can be used to accomplish this.
If I create a new Xcode project and add the code to redirect stderr then everything works as expected.
However, when I add the redirection code to my existing, bluetooth project I am having trouble. The file is being created and I can retrieve it using iTunes or Xcode's Devices window, but it is of size 0. If I explicitly close the file then the text that I wrote actually makes it into the file. It is as though iOS is not flushing the file when the app is terminated. I suspect that the trouble stems from the fact that I have enabled background processing. Can anyone help me to understand this?
Here is my code:
let pathes = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true);
let filePath = NSURL(fileURLWithPath: pathes[0]).URLByAppendingPathComponent("Test.log")
freopen(filePath.path!, "a", stderr);
fputs("Hello, Samantha!\r\n", stderr);
struct StderrOutputStream: OutputStreamType {
static let stream = StderrOutputStream()
func write(string: String) {fputs(string, stderr)}
}
var errStream = StderrOutputStream.stream
print("Hello, Robert", toStream: &errStream)
fclose(stderr) // Without this the text does not make it into the file.
I'd leave this as a comment, but have you looked into NSFileHandle? It sounds like you just need a way to append data to the end of a text file, correct?
Once you have a handle with something like NSFileHandle(forWritingToURL:), you can use .seekToEndOfFile() and .writeData(_:). As a side note, you'll need to convert your String to Data before writing it.
Admittedly, this will probably end up being more lines of code, and you'll almost certainly need to take threading into consideration.

Resources