Empty Arrays and iOS 7 SDK - arrays

Just updated my XCode from 4.6 to 5, and along with it the iOS7 SDK.
I noticed that all operations (e.g. Predicate filters etc) I attempt to perform on empty NSArray or NSMutableArray cause an exception (NSInvalidArgumentException) when running my app in the simulator for either iOS 5.1 or iOS 7 (still struggling to download iOS 6.1)
My arrays are instantiated (so they are not Nil), but they have 0 entries.
So code that used to work fine in XCode 4.6 now crashes, and I have to add an extra IF to check if the array.count == 0 before running that line of code all over my app. (Monumental task)
When I download my app (version I published with XCode 4.6) from the AppStore to an iOS7 device, it works just fine.
Anyone else also experiencing this?

based on this code, I think the value stored in [defaults objectForKey:#"Wards"] is not an array, please double check the value
NSArray *SelectedWards = [[NSArray alloc]initWithArray:[defaults objectForKey:#"Wards"]];
you may use following code to check
if(![[defaults objectForKey:#"Wards"] isKindOfClass:[NSArray class]])
{
NSLog("OOPs! Wards is not an array");
}

Related

From iOS Objective-C code and Android Java code to a Codename One PeerComponent

At the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-ios there are the following examples:
if (self.goCoder != nil) {
// Associate the U/I view with the SDK camera preview
self.goCoder.cameraView = self.view;
// Start the camera preview
[self.goCoder.cameraPreview startPreview];
}
// Start streaming
[self.goCoder startStreaming:self];
// Stop the broadcast that is currently running
[self.goCoder endStreaming:self];
The equivalent Java code for Android is reported at the page https://www.wowza.com/docs/how-to-build-a-basic-app-with-gocoder-sdk-for-android#start-the-camera-preview, it is:
// Associate the WOWZCameraView defined in the U/I layout with the corresponding class member
goCoderCameraView = (WOWZCameraView) findViewById(R.id.camera_preview);
// Start the camera preview display
if (mPermissionsGranted && goCoderCameraView != null) {
if (goCoderCameraView.isPreviewPaused())
goCoderCameraView.onResume();
else
goCoderCameraView.startPreview();
}
// Start streaming
goCoderBroadcaster.startBroadcast(goCoderBroadcastConfig, this);
// Stop the broadcast that is currently running
goCoderBroadcaster.endBroadcast(this);
The code is self-explaining: the first blocks start a camera preview, the second blocks start a streaming and the third blocks stop it. I want the preview and the streaming inside a Codename One PeerComponent, but I didn't remember / understand how I have to modify both these native code examples to return a PeerComponent to the native interface.
(I tried to read again the developer guide but I'm a bit confused on this point).
Thank you
This is the key line in the iOS instructions:
self.goCoder.cameraView = self.view;
Here you define the view that you need to return to the peer and that we can place. You need to change it from self.view to a view object you create. I think you can just allocate a UIView and assign/return that.
For the Android code instead of using the XML code they use there you can use the WOWZCameraView directly and return that as far as I can tell.

Application getting crashed on setting the vocabulary for carName using Siri Kit

I am trying to develop an application using SiriKit to get the car door lock status and set the same from Siri. I followed this blog https://www.appcoda.com/sirikit-introduction/ and did all the setup replacing the INStartWorkoutIntent with INGetCarLockStatusIntent.
But when i try to set the vocabulary for carName, the application is getting crashed with following exception,
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Illegal attempt to provide vocabulary of type INVocabularyStringTypeCarName by an app that does not handle any intents that could use that type of vocabulary'
The source code that i am using to set the vocabulary is,
INPreferences.requestSiriAuthorization { (status) in
}
INVocabulary.shared().setVocabularyStrings(["benz", "bmw", "audi"], of: .carName)
In AppDelegate, i have added the following method,
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {
guard let intent = userActivity.interaction?.intent as? INGetCarLockStatusIntent else {
print("AppDelegate: Start Workout Intent - FALSE")
return false
}
print("AppDelegate: Start Workout Intent - TRUE")
print(intent)
return true
}
Also created the extension for intent handler and implemented INSetCarLockStatusIntentHandling, INGetCarLockStatusIntentHandling protocols. I am getting this issue when i try to run it in iPhone 10.
Check, if in TARGETS of your project in Build Phases->Embed App Extensions added your Siri Extension. Maybe if you replace the INStartWorkoutIntent with INGetCarLockStatusIntent, old INStartWorkoutIntent remained there.
My crash fix this.
I was facing a similar issue. Make sure your extension's Deployment Target is set to appropriate iOS version. Creating an extension with the latest Xcode (at the moment 10.1) will set the Deployment Target to 12.1 and thus cause crash when run on iOS 10. So you should change it to your desired minimum.

UIActivityViewController showing "Unable to Load" row in iOS 11

I was using a UIActivityViewController instance in several previous versions of an app in order to share content through AirDrop, and other services. And now, without even recompiling, when running the app in iOS 11 Beta, the dialog (UIActivityViewController instance) shows the following row with the message "Unable to load":
Here is the code:
let handlerOk = { () -> Void in
let activityItems = [NSURL(fileURLWithPath: fullPath, isDirectory: true)]
self.viewControllerShare = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
if let viewControllerShare = self.viewControllerShare {
viewControllerShare.popoverPresentationController?.sourceView = sender
let excludedActivities = [
UIActivityType.postToFacebook,
UIActivityType.postToTwitter,
UIActivityType.postToWeibo,
//UIActivityType.message,
//UIActivityType.mail,
UIActivityType.print,
UIActivityType.copyToPasteboard,
UIActivityType.assignToContact,
UIActivityType.saveToCameraRoll,
UIActivityType.addToReadingList,
UIActivityType.postToFlickr,
UIActivityType.postToVimeo,
UIActivityType.postToTencentWeibo,
UIActivityType.openInIBooks
]
viewControllerShare.excludedActivityTypes = excludedActivities
self.present(viewControllerShare, animated: true, completion: nil)
}
}
Right now I'm compiling with XCode 9 in Swift 4, but I don't think this is relevant since as said, if an older version of the app is run in iOS 11 (compiled with XCode 8.somenthing or even downloading the binary from TestFlight) the problem is the same. So this really looks like an iOS 11 API problem...
Is there anything new regarding the dialog initialization that may prevent the "Unable to load" row to appear?
EDIT: I tested a third party app (from Apple) that uses the same sharing dialog, and found that that row belongs to iCloud. But I'm not using iCloud in my app, so the previous UIActivityViewController behaviour was correct: it just did not show anything. So I made an experiment: disabled from iOS' Settings the iCloud permission for that third party app, and it showed the same unkind "Unable to load" message. I hope this is not the way that the final iOS 11 version works, and that it's just a Beta problem.
That said, workarounds are still welcome! Thanks!

android calendar crashes where iOS is working

My app crashes with NullPointerException, since the android calendar does not return a Collection of calendar names from the dc.getCalendars(); function from the CN1 Calendar Lib, even though it is working to this point on the iOS iphone version.
Device Calendar dc = DeviceCalendar.getInstance();
Collection<String> calNames = dc.getCalendars();
String [] nameArray = calName.toArray(new String[calName.size()]);
Its throwing me an NullPointerException for the 3rd line because calName is a null object and I cant use size() on it. Again, the code IS working on iPhone, so it seems there is a problem with android.
Thanks in advance.
The javadocs for that method say that getCalendars() will return null if you don't have permission
https://github.com/sidiabale/codenameone-calendar/blob/master/CN1Calendar/src/com/codename1/calendar/DeviceCalendar.java#L91
You'll need to add the permissions using the android.xpermissions build hint.
codename1.arg.android.xpermissions=<uses-permission android:name="android.permission.READ_CALENDAR"/> <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
And it looks like you also need to set android.targetSDKVersion=21
See this SO thread for a related issue.

OpenCV Capture from external camera

I'm currently writing an real time application using OpenCV and in the following case:
I'm trying to capture an image from a HDV camera plugged in firewire 800.
I have tried to loop on index used on cvCaptureFromCam,
but no camera can't be found (except the webcam).
there is my code sample, it loop on index (escaping 0 cause it's the webcam's index) :
CvCapture* camera;
int index;
for (index = 1; index < 100; ++index) {
camera = cvCaptureFromCAM(index);
if (camera)
break;
}
if (!camera)
abort();
On any time it stops on the abort.
I'm compiling on OSX 10.7 and I have tested :
OpenCV 1.2 private framework
OpenCV 2.0 private framework (found here : OpenCV2.0.dmg)
OpenCV compiled by myself (ver. 2)
I know that the problem is knowned and there is a lot of discussion about this,
but I'm not able ti find any solution.
Does anyone have been in the same case ?
Regards.
To explicitly select firewire, perhaps you can try to add 300 to your index? At least in OpenCV 2.4, each type of camera is given a specific domain. For example, Video4Linux are given domain 200, so 200 is the first V4L camera, 201 is the second, etc. For Firewire, the domain is 300. If you specify an index less than 100, OpenCV just iterates through each of its domains in order, which may not be the order you expect. For example, it might find your webcam first, and never find the firewire camera. If this is not the issue, please accept my appologies.
index should start at 0 instead of 1.
If that doesn't work, maybe your camera is not supported by OpenCV. I suggest you check if it is in the compatibility list.

Resources