Replacement for DeviceInfo in phonegap > 1.5 - ios

It seems that they have deprecated the Phonegap variable DeviceInfo as of Cordova 1.5 (I think I saw that it was technically deprecated for 1.5 as well, but left it in). I know there is the device variable, but I was using the DeviceInfo variable to store some of my own data via the callback to
- (NSDictionary*)deviceProperties{...}
It seems that function is still called for the var device data, but it doesn't let me add any data to that variable. Does anyone know if there is anyway to get back the functionality of having custom device data or is it gone forever?

OK so the workaround I came up with was to simply create the variable myself in a javascript call so that the rest of the javascript code still access it as needed. I etd a catagory to override
- (void)viewDidAppear:(BOOL)animated;
and in the implementation I called the following code
NSString* jsString = [NSString stringWithFormat:#"window.DeviceInfo = {param1:%#, param2:%#}}", param1, param2];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
That added code allowed for backward compatibility with code based on the editable DeviceInfo variable that has been removed.

Related

NativeScript: Get string from interop.reference

To start, here is my code:
var buffer = malloc(interop.sizeof(interop.types.UTF8CString));
var fillBuffer = mac.getBytes(buffer);
var bytes = new interop.Reference(interop.types.UTF8CString, buffer);
var hexMac = bytes[0];
The variable 'Mac' is an NSData objected retrieved from CoreBluetooth. It is the scan response from a BLE device, which contains the peripheral's MAC address (00:0b:57:a2:fb:a0).
This problem is linked to THIS question I had posted earlier.
The solution provided is great; however, I cannot seem to implement this in nativescript :
(instancetype)stringWithFormat:(NSString *)format, ...;
Intellisense tells me the method doesnt exist on type NSString.
Due to that issue, I decided to go another route (as you can tell). I am filling a buffer with the bytes of the MAC address. In the code above, bytes[0] equates to 0xb57a2fba0.
I am now trying to convert that (which is an interop.Reference) into a string that I can store on the back-end (preferably in the xx:xx:xx:xx:xx format).
I have been at this all weekend, and cannot seem to find a solution. I even broke down objc!foundation.d.ts to figure out if stringWithFormat was supported, to no avail.
The nativescript community slack was unable to provide a resolution as well.
Please help if you can!
I don't know anything about NativeScript at all, but given the other code you wrote, I assume you're calling +alloc first, and so mean to use -initWithFormat: (an instance method that initializes) rather than +stringWithFormat: (a class method which handles allocation and initialization).

App is referring to old values in constants file after updating

I’m maintaining two constants files in my app where in which one file contains all the constants defined using #define and other file contains all the constants defined using:
static NSString const *holidaysearch = #"holidaySearch"
Basically I use them for forming the URL for server calls. Our app is already in app store. So in a update to my app that I published last week I have made changes to both constant file by modifying the values only.
For e.g.:
static NSString const *holidaysearch = #"getholidaySearch"
(When means in real time in my app I have changed a url). But when user is updating the app and running the app the constant is still referring to the old value (i.e holidaysearch) due to which we are facing some issues. But it's working fine when the user is installing latest version directly. So is there any concept of iOS caching the constants file while updating the app or anything else needed to be done? Suggest me fix for this.
I would start by changing all of your #define constants to NSString * const. Also, static NSString const *holidaysearch should be static NSString * const holidaysearch. Here's an explanation as to why.

get mediaSessionID for the current media playing on chrome cast in Swift on iOS

I'm referring to https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_media_status.html#a45e3eb39e674f5d0dbfd78deef77a1e6
that helps me with the api, but the initializer for the GCKMediaStatus class says:
- (instancetype) initWithSessionID: (NSInteger) mediaSessionID
mediaInformation: (GCKMediaInformation *) mediaInformation
note: this is in Objective-c syntax but Swift works just the same except in Swift language...
Nonetheless I can't seem to figure out how to retrieve the mediaSessionID to be able to initialize an instance of this class to a new variable.
I'm trying to do the following to get me eventually to the method within this class called streamPosition which would go like this:
var mediaStatus = GCKMediaStatus(sessionID: Int, mediaInformation: GCKMediaInformation!)
var currentStreamPosition = mediaStatus.streamPosition()
where Int would be the mediaSessionID NOT the sessionID of the chrome cast (read the additional section below!!) and GCKMediaInformation! would be an instance of the GCKMediaInformation class. (I think) correct me if I'm wrong on either of those parameters.
Then I could use this data. But when I do this the currentStreamPosition I suppose defaults to 0 and thats what I get when I print to the currentStreamPosition variable.
Note: I've already connected to the current playing media and I am able to pause, play, and seek to an arbitrary number within the stream. This all works. So I now I'm connected and everything else works.
use case: I want to be able skip ahead 15 seconds or rewind 15 seconds etc. with the use of this method, but I haven't found anything to help.
also - don't get sessionID confused with mediaSessionID!! I CAN get the sessionID successfully and print it out. My issue is with the mediaSessionID.
additional info: the autocomplete is Xcode says this is the parameters labeled names:
GCKMediaStatus(sessionID: Int, mediaInformation: GCKMediaInformation!)
note the first parameter says sessionID and it is of type int. But on https://developers.google.com/cast/docs/ios_sender if you notice sessionID is of type String! (an optional String).
I think this label was mis-named in Xcode for the autocomplete. I think it should be named mediaSessionID and NOT sessionID since this is what the documentation shows on the first link I provided.
Any help would be much appreciated.
Thanks!
To get the stream position, use the method approximateStreamPosition on GCKMediaControlChannel.

Xamarin - NSURL returning null

I am building an app using Xamarin's Unified API and am creating a NSUrl with a string. However the app crashes as soon as I try to create the NSUrl.
string url = "comgooglemaps-x-callback://?daddr=" + destination;
NSUrl googleMapsURL = new NSUrl (url);
The value of url is comgooglemaps-x-callback://?daddr=600+Drake+Apartments\n600+Drake+St,+Vancouver+BC+V6B+5W7,+Canada
The message in the console is:
Could not initialize an instance of the type 'Foundation.NSUrl': the
native 'initWithString:' method returned nil. It is possible to ignore
this condition by setting
MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.
How do I fix this ?
This will work (tested with your above code).
using System.Web.Services;
...
string destination = System.Web.HttpUtility.UrlEncode(
"600 Drake Apartments\n600 Drake St, Vancouver BC V6B 5W7, Canada");
Now turns into
"comgooglemaps-x-callback://?daddr=600+Drake+Apartments%0a600+Drake+St%2c+Vancouver+BC+V6B+5W7%2c+Can…"
Add Reference System.Web.Services to the project. My guess is that your URL encoding, wherever it's coming from isn't compatible with what the Apple APIs expect.

MECL Paypal convert to ARC (IOS)

I am currently trying to integrate Paypal's MECL in an already existing IOS project using ARC.
I believe that by manually removing all the release / retain in the code should make it ARC compatible.
There is only one statement I do not know how to convert: "InitAndDealloc" that can be find in several class such as here:
static NSString *SolutionTypeStrings[] = {#"Sole", #"Mark"};
static NSString *LandingPageTypeStrings[] = {#"LandingPage", #"Billing", #"Login"};
static NSString *ChannelTypeStrings[] = {#"Merchant", #"eBayItem"};
#define LOCALE_CODE #"LocaleCode"
#implementation SetExpressCheckoutRequestDetails
InitAndDealloc
StringAccessor(ReturnURL)
StringAccessor(CancelURL)
StringAccessor1(cppHeaderImage, #"cpp-header-image")
StringAccessor1(cppHeaderBorderColor, #"cpp-header-border-color")
StringAccessor1(cppHeaderBackColor, #"cpp-header-back-color")
StringAccessor1(cppPayflowColor, #"cpp-payflow-color")
IntAccessor(AllowNote)
IntAccessor(ReqConfirmShipping)
TypedefAccessor(NoShipping, NoShippingType)
StringAccessor(Token)
AmountAccessor(MaxAmount)
StringAccessor(CallbackURL)
IntAccessor(CallbackTimeout)
GenericAccessor1(FlatRateShippingOptions, ShippingOptions)
IntAccessor(AddressOverride)
StringAccessor(PageStyle)
StringAccessor(BuyerEmail)
StringAccessor(giropaySuccessURL)
StringAccessor(giropayCancelURL)
StringAccessor(BanktxnPendingURL)
GenericAccessor(EnhancedCheckoutData)
GenericAccessor(BuyerDetails)
StringAccessor(BrandName)
GenericAccessor(FundingSourceDetails)
StringAccessor(CustomerServiceNumber)
IntAccessor(GiftMessageEnable)
IntAccessor(GiftReceiptEnable)
IntAccessor(GiftWrapEnable)
StringAccessor(GiftWrapName)
AmountAccessor(GiftWrapAmount)
IntAccessor(BuyerEmailOptinEnable)
StringAccessor(SurveyQuestion)
StringAccessor(CallbackVersion)
IntAccessor(SurveyEnable)
MutableArrayAccessor(PaymentDetails)
MutableArrayAccessor(BillingAgreementDetails)
MutableArrayAccessor1(OtherPaymentMethods, OtherPaymentMethodDetails)
MutableArrayAccessor1(SurveyChoice, NSString)
EnumAccessor(SolutionType, SolutionType)
EnumAccessor(LandingPage, LandingPageType);
EnumAccessor(ChannelType, ChannelType);
If I remove the line "InitAndDealloc", it seems as if I cannot set the variables anymore in the class. Indeed, I have also the working (Non ARC) paypal demo.
By doing this:
SetExpressCheckoutRequestDetails *sreq = [[SetExpressCheckoutRequestDetails alloc] init];
sreq.ReturnURL = #"Bob";
NSLog(#"%# ", sreq.ReturnURL );
In both projects.
Mine will return null, paypal's will return the Bob.
Has it even got anything to do with "InitAndDealloc" or am I looking at it wrong? If it is how do I replace "InitAndDealloc" in an ARC project? I can't seem to find a simple "Init" with autocompletion and by googling "InitAndDealloc" I get absolutely no results whatsoever :/
Thanks for reading!
I've never used MECL before but the way it's being called "InitAndDealloc" certainly is not Objective C and therefore wouldn't be subject to the same rules that ARC requires for Objective C. Best to leave it in place and not try to futz or struggle with it.
But anyways, instead of struggling with trying to ARC-enable some published & potentially-problematic SDK code, why not turn ARC off for the MECL files?
Here is a related question that describes how to turn ARC off for individual files.

Resources