Why would `mediaCapture.captureImage()` crash my `ionic` app? - ios

I'm building an IOS app in ionic that captures media (photo, video, audio) and ran into a quite confounding issue today. I'm using the following 3 methods (on MediaCapture):
captureImage()
captureVideo()
captureAudio()
The only one that doesn't work is captureImage() and I can't, for the life of me, figure out why. Side note: I was able to use camera.getPicture() but I'd like to use MediaCapture for all 3 media types (and it doesn't make sense why I can't).
Here are some details:
Environment
OS: Mac OS 10.12.6
Node: 9.0.0
ionic: 3.15.2
Cordova: 7.1.0
iOS: 11.1
I'm running the app on my device using ionic cordova run ios -l -c -s.
Sample code
Example Code (extracted Typescript)
private media: object = {
'image': 'captureImage',
'video': 'captureVideo',
'audio': 'captureAudio'
};
function captureMedia(media) {
console.log('capturing');
const options: CaptureImageOptions = {
limit: 1
};
this.mediaCapture[this.media[media]](options)
.then(
(data: MediaFile[]) => console.log(JSON.stringify(data)),
(err: CaptureError) => console.error(JSON.stringify(err))
);
}
captureMedia('image'); // CRASHES!!
captureMedia('audio'); // WORKS!
captureMedia('video'); // WORKS!
No output. No warnings. No console output. Just kaput!
I feel like I'm missing something here but I can't see what it is. Can anyone help?

So, I ended up attempting to run this on my device from Xcode and finally got a useful error message! It turns out, my config.xml was missing one property for privacy permissions.
This was the one that was missing:
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryAddUsageDescription">
<string>Allow photo library access.</string>
</edit-config>
Remember, you'll also need descriptions for the following (which I had):
NSCameraUsageDescription
NSMicrophoneUsageDescription
NSPhotoLibraryUsageDescription
Cheers!

Related

Firebase analytics with latest Ti SDK 9.0.3 GA having issue for screen_view

I tried using Firebase with previous version of Ti SDK (7.5.2). Where both FIRAnalytics.setScreenName and FIRAnalytics.logEventWithName (methods of ti.firebase, equality method in other modules) working fine.
Initial thought was, may be module problem. But reading few blog posts understand Firebase will track screen views automatically https://firebase.google.com/docs/analytics/screenviews .
Of-course we can also call manually.
If my guess is right, on app launch firebase started tracking screen time and we are getting below error. (I tried with ti.firebase, firebase.analytics and own sample native mobile for ios)
objc[67740]: Cannot form weak reference to instance (0x7f9ab8e0aac0)
of class UIViewController. It is possible that this object was
over-released, or is in the process of deallocation.
I found an alternative to turn off screen tracking. By adding FirebaseScreenReportingEnabled to false in Project's info.plist. For Titanium project we need to add in tiapp.xml . And This time we did not see any issue and log event is working fine. But I did not see any screen views, even manual. Because this option will totally block screen trackings.
:
<ios>
<enable-launch-screen-storyboard>true</enable-launch-screen-storyboard>
<use-app-thinning>true</use-app-thinning>
<plist>
<dict>
:
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleDefault</string>
<key>FirebaseScreenReportingEnabled</key>
<false/>
</dict>
</plist>
</ios>
:
But this even not tracking manually screen views. So we are losing a track of avg screen time.
Here the example of ti.firebase (I tried with firebase.analytics unfortunately I can refer the sample code here, but we can use this https://github.com/hansemannn/titanium-firebase-analytics/blob/master/example/app.js)
var _tFireb = require('ti.firebase');
_tFireb.configure();
function doClick(e) {
alert($.label.text);
var logParams = {
'name': "button_clicked",
'parameters': null
};
//Ti.API.info("Sending logEvtData", logParams);
_tFireb.FIRAnalytics.logEventWithName(logParams);
}
$.index.open();
_tFireb.FIRAnalytics.setScreenName({
'screenName' : "indexdefault",
'screenClass' : "indexdefault"
});
We tried with latest titanium-firebase-analytics module. It is working fine.
https://github.com/hansemannn/titanium-firebase-analytics/releases/tag/ios-2.0.0
There is change in Firebase itself. Now sending Screenview also same like log event by passing constant. Note: if you pass "screen_view" it will not work.
you need to use const like below, module is already taken care of it.
[FIRAnalytics logEventWithName:kFIREventScreenView parameters:]

Why can't I share both message and image in MMS cordova ios using cordova-plugin-x-socialsharing

I have included the cordova-plugin-x-socialsharing
in my cordova project so I can use the MMS capabilities to share a message and image. This works fine on Android, but I am having problems with iOS. I can share text or an image, but I cannot share both together. Everything seems to work, and the native interface is opened, but if an image is present then the text is missing. I have no idea what might be the issue, I've tried searching the web for similar situations but can't find anything related. However, according to the cordova-plugin-x-socialsharing docs, it appears this is an issue with WhatsApp, but not MMS. If anyone has any ideas about what is causing this problem, or what I can do to fix it, that would be greatly appreciated.
I have included the cordova-plugin-x-socialsharing plugin in my config.xml like this:
<plugin name="cordova-plugin-x-socialsharing" spec="~5.6.5" />
The code I am using to send the message is as follows:
window.plugins.socialsharing.shareViaSMS(
{
message: "Test Message #helloworld",
subject: "Test Message #helloworld",
image: this.shareImageURL //local file system url
},
this.phoneNumber.replace(/\D/g, ""),
function() {
that.showPhoneNumber = false;
that.phoneNumber = null;
},
function(e) {
alert("An Error Occured While Sharing: " + JSON.stringify(e));
that.showPhoneNumber = false;
that.phoneNumber = null;
}
);
Again, I can share the image just fine, but the subject/message will not be included if I share the image. I've tried many different combinations, but nothing has worked so far
Base on the official github already declare iOS will not work message/subject with image together. Either one will share to whatsapp only.
Reference : https://github.com/codeborne/cordova-plugin-x-socialsharing#whatsapp

Ionic 2 Camera select Video on iOS not working

I'm developing a App with Ionic 2 and I'm have problems with #ionic-native/Camera. I've this code on Upload.ts
let loader = this.loading.create({
content: 'Carregando video....'
});
loader.present().then(() => {
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
mediaType: this.camera.MediaType.VIDEO,
}
this.camera.getPicture(options).then((videoData) => {
this.uploadForm.controls['file'].setValue(videoData)
loader.dismiss();
}, (err) => {
console.log(err);
});
});
This code works fine in Android, but when I run ionic cordova run ios -lc, the promise this.camera.getPicture(options) is never resolved, so the loader keep running forever.
Thanks in advance!
So, I found the problem. First thing is that native components bugs with -l (--livereload). I don't know how to explain why but I got this information from the Ionic Worldwide slack. A member from Ionic Team said:
"live-reload on a device can cause issues with plugins and file system".
So I used this video to understand how to debbug the APP using the iOS emulator and Safari.
https://www.youtube.com/watch?v=Aob749bkoLY
A little brief of the video: when using iOS emulator, you can access the menu Developer > Emulator > <App Name>. A new window with inspector tools will open and logs from the emulator will appear on this window.
I found out that's the video url was incorrect. Before, to be compatible with Android, I've this code responsible to find the video pointer in system and send to the server:
filePath = 'file:///' + this.uploadForm.controls['file'].value;
But, iOS File Picker already has a "file:///" prefix. So prefixing it again made it wrong. So I updated the code to be like this:
if (this.platform.is('android')) {
filePath = 'file:///' + this.uploadForm.controls['file'].value;
} else {
filePath = this.uploadForm.controls['file'].value;
}
This resolved the problem.

Google Places Callback not being called in Swift iOS

I am using the GoogleMaps SDK (maps & places). For some reason the following callback is not being called. I have put loggers in there but nothing happens.
var placesClient : GMSPlacesClient?
...
func run(){
self.placesClient?.currentPlaceWithCallback({ (list: GMSPlaceLikelihoodList?, error: NSError?) -> Void in
if let error = error {
println("error: \(error.description)")
return
}
if let list = list {
self.renderList(list)
}
})
}
For some reason the block in currentPlaceWithCallback does not get called. Yesterday it happened because my API had a wrong bundle identifier, after changing which it started working. But today it stopped.
Any idea why this would happen ? Also, are we exposed to any API logs by Google ?
I was getting the same issue on my iPhone 6 device AND iPhone 6 simulator.
The fix was to add the NSLocationWhenInUseUsageDescription permission in Info.plist! But, it worked only on my iPhone 6 device, NOT the simulator.
As mentioned in the Google Place Guide:
(https://developers.google.com/places/ios-api/start)
Please note, as this sample requires access to the location of the device to get the current location, you will need to set the NSLocationWhenInUseUsageDescription key with appropriate explanatory text in your project's Info.plist file. For more details, see the guide to getting current place.
Now, the way I got it working on the iPhone simulator was by changing my location on the Simulator: Debug -> Location. That is, it was set to 'Apple' by default, I just changed it to Bicycle Ride.
It worked for me, may not for all.

cordova ios resolveLocalFileSystemURL ENCODING_ERR in cordova.file.applicationDirectory

window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + 'www/tutorial/comic.json')
results in the failure callback with ENCODING_ERR on device. Works FINE in ios simulator.
iosPersistentFileLocation = Library
iosExtraFilesystems = bundle, library, library-nosync
full paths:
on the device-
file:///private/var/mobile/Containers/Bundle/Application/0E3CD0FD-BC69-42D1-BBB2-C59682E7F29A/My%20Comics.app/www/tutorial/comic.json
simulator-
file:///Users/admin/Library/Developer/CoreSimulator/Devices/80E29D25-5164-4869-81F9-E30571D2BE92/data/Containers/Bundle/Application/650AE88A-FD42-469B-90FE-494DF11CFA02/My%20Comics.app/www/tutorial/comic.json
You neeed root in your iosExtraFilesystems. Even though the docs say it loaded by default. This fixed it.
iosExtraFilesystems = root, bundle, library, library-nosync
Maybe this may help anybody who struggles with this too ... we had the exact same effect
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory ) always faild with FileError 5 (ENCODING_ERROR)
on real device (iPadAir 4th Gen) -> Always File Error 5
But it worked on The iPadAir Simulator(4.th Gen) without problems ...
after hours and hours bangign our heads against all walls in the office
We were able to resolve this by: "not using es6" in the callback for success --- the good old way works on Simulator & Device
CONST filePath = cordova.file.applicationDirectory + "www/" window.resolveLocalFileSystemURL(filePath , function(fileEntry){ ... });
instead of fileEntry => { ...

Resources