TypeError: Cannot read property 'name' of undefined ionic - ios

I am making a project in Ionic.
When I tried ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0" an error occurred
TypeError: Cannot read property 'name' of undefined
To know the deeper cause --verbose when using
at /Users/myname/ionic/platforms/ios/cordova/lib/build.js:130:60
I was able to identify this as the source of the error but I don't know this error solution.
var promise = require('./list-emulator-build-targets').targetForSimIdentifier(newTarget);
return promise.then(function (theTarget) {
if (!theTarget) {
return getDefaultSimulatorTarget().then(function (defaultTarget) {
emulatorTarget = defaultTarget.name;
events.emit('log', 'Building for ' + emulatorTarget + ' Simulator');
return emulatorTarget;
});
} else {
emulatorTarget = theTarget.name;
events.emit('log', 'Building for ' + emulatorTarget + ' Simulator');
return emulatorTarget;
}
});

this error course MacOS Catalina
https://github.com/apache/cordova-ios/issues/427#issuecomment-503522317
fix code platform/ios/cordova/liblist-emulator-build-targets
var availableDevices = Object.keys(devices).reduce(function (availAcc, deviceCategory) {
var availableDevicesInCategory = devices[deviceCategory];
availableDevicesInCategory.forEach(function (device) {
if (device && device.name === deviceType.name.replace(/\-inch/g, ' inch') && device.isAvailable == true) {
availAcc.push(device);
}
});
return availAcc;
}, []);

Related

mp3 won't play on ios

I'm getting this error when i'm trying open audio mp3 files on ios:
Error status: 9 - Error message: Could not handle UTI
I'm using cordova-plugin-file-opener2 2.2.1
My code:
var local_file = cordova.file.dataDirectory + '1579617669858mp3';
cordova.plugins.fileOpener2.open(local_file, "audio/*", {
error: function (e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
if (e.status === 9) {
AlertInfo("Player must be installed on your device");
}
},
success: function () {
console.log("success");
}
});

Cordova: Invalid data, chunk must be a string or buffer, not object

I updated to Ionic 3.5, and after that I get this error, when i try to do cordova build ios:
Invalid data, chunk must be a string or buffer, not object
There is no explanation of why this error is happening. I tried this both with Cordova 7.0.1 and 6.5.0. Interestingly, it works on Windows machine, but not on Mac. I only get the error on Mac. I appreciate any insights or helps.
ionic info
global packages:
#ionic/cli-utils : 1.5.0
Cordova CLI : 7.0.1
Ionic CLI : 3.5.0
local packages:
#ionic/app-scripts : 1.3.7
#ionic/cli-plugin-cordova : 1.4.1
#ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.5.3
System:
Node : v7.10.0
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 4.6.1
I got the fix from one of the github issue. It just needed correct path for strings.xml.
There is no need to downgrade cordova or cordova-android
The fix is to replace the code in
/cordova-plugin-fcm/scripts/fcm_config_files_process.js as below:
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var path = require('path');
fs.ensureDirSync = function (dir) {
if (!fs.existsSync(dir)) {
dir.split(path.sep).reduce(function (currentPath, folder) {
currentPath += folder + path.sep;
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
return currentPath;
}, '');
}
};
var config = fs.readFileSync('config.xml').toString();
var name = getValue(config, 'name');
var IOS_DIR = 'platforms/ios';
var ANDROID_DIR = 'platforms/android';
var PLATFORM = {
IOS: {
dest: [
IOS_DIR + '/' + name + '/Resources/GoogleService-Info.plist',
IOS_DIR + '/' + name + '/Resources/Resources/GoogleService-Info.plist'
],
src: [
'GoogleService-Info.plist',
IOS_DIR + '/www/GoogleService-Info.plist',
'www/GoogleService-Info.plist'
]
},
ANDROID: {
dest: [
ANDROID_DIR + '/google-services.json',
ANDROID_DIR + '/app/google-services.json',
],
src: [
'google-services.json',
ANDROID_DIR + '/assets/www/google-services.json',
'www/google-services.json'
],
stringsXml: ANDROID_DIR + '/app/src/main/res/values/strings.xml'
}
};
// Copy key files to their platform specific folders
if (directoryExists(IOS_DIR)) {
copyKey(PLATFORM.IOS);
}
if (directoryExists(ANDROID_DIR)) {
copyKey(PLATFORM.ANDROID, updateStringsXml)
}
function updateStringsXml(contents) {
var json = JSON.parse(contents);
var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString();
// strip non-default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^\#<]+?)</string>', 'i'), '');
// strip non-default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^\#<]+?)</string>', 'i'), '');
// strip empty lines
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1');
// replace the default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)</string>', 'i'), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>');
// replace the default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)</string>', 'i'), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>');
fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings);
}
function copyKey(platform, callback) {
for (var i = 0; i < platform.src.length; i++) {
var file = platform.src[i];
if (fileExists(file)) {
try {
var contents = fs.readFileSync(file).toString();
try {
platform.dest.forEach(function (destinationPath) {
var folder = destinationPath.substring(0, destinationPath.lastIndexOf('/'));
fs.ensureDirSync(folder);
fs.writeFileSync(destinationPath, contents);
});
} catch (e) {
// skip
}
callback && callback(contents);
} catch (err) {
console.log(err)
}
break;
}
}
}
function getValue(config, name) {
var value = config.match(new RegExp('<' + name + '>(.*?)</' + name + '>', 'i'));
if (value && value[1]) {
return value[1]
} else {
return null
}
}
function fileExists(path) {
try {
return fs.statSync(path).isFile();
} catch (e) {
return false;
}
}
function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
} catch (e) {
return false;
}
}
For fixing the issue:
Make sure you have copied the above file in "plugins" folder as cordova copies all the cordova-plugins from node_modules directory to plugins directory,
if you have already added the platforms before modifying the file
plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js, you need to remove the platforms and add again.
#Ari In case you are still having this issue, this is what I did to solve this issue.
I had to edit file "fcm_config_files_process.js" located in folder "plugins/cordova-plugin-fcm/scripts/":
// fs.writeFileSync("platforms/ios/" + name + "/Resources/GoogleService-Info.plist", contents)
For some unknown reason while building the project this line (42) was throwing the error "Invalid data, chunk must be a string or buffer, not object" so what I did was to comment that line and then manually copy the file "GoogleService-Info.plist" to "platforms/ios/" + name + "/Resources/"
Hope this help.
We had this error because our Development Push Certificate from apple was outdated. We have renewed it – and it worked.
Remove default added ios platform when creating Ionic 2 app then add again.
And also remove and add "cordova-fcm-plugin".
ionic platform rm ios
ionic platform add ios

cordova-plugin-media-with-compression error on IOS when recording

I am using cordova-plugin-media-with-compression for an app which runs on IOS and Android. On Android the code is working perfectly, records, play, stop, erase, no problem. On IOS I can play the files saved using the android app, but as soon as I try to record I get error 1 which is MEDIA_ERR_ABORTED (no idea what that means). So works perfectly on Android, but will not record on IOS. I am also using cordovafile for other things and they work, so I know cordova file is working and I verified that I am getting a legitimate folder for the mediapath.
I used the code right out of the example.
$scope.mediapath = cordova.file.externalApplicationStorageDirectory || cordova.file.tempDirectory || cordova.file.sharedDirectory;
$rootScope.mediaOptions = {
SampleRate: 16000,
NumberOfChannels: 1
};
$scope.mediafile = "record-audio.m4a";
$scope.media = new Media($scope.mediapath + $scope.mediafile, function () {
console.log("recordAudio():Audio Success");
},
function (err) { console.log("recordAudio():Audio Error: " + err.code); },
function (s) {
if (s === 4) {
$timeout(function () {
angular.element(document.getElementById('stopButton')).triggerHandler('click');
}, 0);
}
} );
$scope.media.startRecordWithCompression($rootScope.mediaOptions);
Even though . $scope.mediapath = $scope.mediapath.fullPath; worked for a while, I had further errors and ended up with this solution. Note I keep both mediapath and mediapath1 because when using $cordovaFile.readAsDataURL($rootScope.mediapath, $scope.mediafile)... I need the mediapath for ios and android.
$rootScope.mediaOptions = {
SampleRate: 16000,
NumberOfChannels: 1
};
$rootScope.mediapath = cordova.file.tempDirectory || cordova.file.dataDirectory || cordova.file.externalApplicationStorageDirectory || cordova.file.sharedDirectory || cordova.file.applicationStorageDirectory;
$rootScope.mediapath1 = $rootScope.mediapath;
if (cordova.platformId === 'ios') {
$rootScope.mediapath1 = '';
}
then when I need to initialize the media
$scope.mediafile = "audio.m4a";
$scope.media = new Media($rootScope.mediapath1 + $scope.mediafile,
function () {
console.log("recordAudio():Audio Success");
},
function (err) { console.log("recordAudio():Audio Error: " + err.code + err.message); },
function (s) {
// catch change to audio here for example when s===4 the recording has been stopped.
}
});
$scope.media.startRecordWithCompression($rootScope.mediaOptions)
;

Grunt / PhoneGap : Warning: stdout maxBuffer exceeded

Quite randomly I get the following message Warning: stdout maxBuffer exceeded when I use my grunt script to launch the iOS simulator.
Any idea what could trigger this ?
Here is the part of my Gruntfile where it occurs :
grunt.registerTask('emulator', 'Launch an emulator', function (platform, targetId) {
if (arguments.length === 0 || !platform) {
grunt.fail.fatal('No platform was specified');
} else {
grunt.log.writeln('We launch the emulator for ' + platform);
if (targetId) {
grunt.log.writeln('Specified targetId: ' + targetId);
}
var fs = require('fs'), execInstance, directoryPath, command, done = this.async();
if (platform === 'ios') {
directoryPath = phoneGapBuildPath + '/platforms/' + platform.toLowerCase() + '/cordova/';
command = './run';
} else {
directoryPath = phoneGapBuildPath + '/platforms/' + platform.toLowerCase() + '/cordova/';
command = 'node run ' + (targetId ? '--target=' + targetId : '--debug');
}
if (!fs.existsSync(directoryPath)) {
grunt.fail.fatal('You need to launch the compile phase');
return;
}
grunt.log.writeln('We run the following command: ' + command);
execInstance = require('child_process').exec(command, {
cwd : directoryPath
}, function (err) {
done(err);
});
execInstance.stdout.on('data', function (data) {
grunt.log.writeln(data);
});
execInstance.stderr.on('data', function (data) {
grunt.log.error(data);
});
}
});
You can use an option to disable maxBuffer :
shell: {
yourCommand: {
command: [
'command to execute'
],
options: {
execOptions: {
maxBuffer: Infinity
}
}
}
}
When you spawn the child process, try bumping maxBuffer in your config object:
execInstance = require('child_process').exec(command, {
cwd : directoryPath,
maxBuffer: 500 * 1024
}, function (err) {
done(err);
});
According to the docs, the default maxBuffer size is 200 * 1024 (http://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback)

Google Gears upload: strange error

I've got this very strange error and I don't know how to deal with it.
My setup is a page in which I can select one image file, (gears beta.desktop) and then it should upload. But it doesn't upload, and gives a very strange error which I can't get away. below is my code:
var filesToUpload = null;
function progressEvent(event) {
var bar = $("#progressBar");
var percentage = Math.round((event.loaded / event.total) * 100);
bar.width(percentage + '%');
}
function uploadState() {
if(request.readyState == 4) {
if(request.status != 200) {
alert('ERROR');
} else {
alert('DONE');
}
}
}
function handleFiles(files) {
if(files.length) {
$('#loader').slideDown(500);
var curFile = files[0];
request.open('POST', 'upload.php');
request.setRequestHeader("Content-Disposition", "attachment; filename=\"" + curFile.name + "\"");
request.onreadystatechange = uploadState;
request.upload.onprogress = progressEvent;
request.send(curFile.blob);
}
}
init = function() {
if(!window.google || !google.gears) {
$('body').css('background', 'white');
$('#gearsOn').hide();
$('#gearsOff').show();
return;
}
// verberg 'geen gears' bericht
$('#gearsOff').hide();
// init upload zooi (gears)
desktop = google.gears.factory.create('beta.desktop');
request = google.gears.factory.create('beta.httprequest');
// on click funct
$('#titel').click(function() {
var newtitle = prompt("Voer een titel in voor het album.");
if(newtitle != '' && newtitle != null) {
$(this).text(newtitle);
}
});
$('.addPictures').click(function() {
filesToUpload = null;
var options = { singleFile: true, filter: [ 'image/jpeg', 'image/png'] };
desktop.openFiles(handleFiles, options);
});
};
$(document).ready(init);
It gives the following error:
[Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsILoadGroup.groupObserver]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: file:///Users/Fabian/Library/Application%20Support/Firefox/Profiles/oo132cjy.default/extensions/%7Be3f6c2cc-d8db-498c-af6c-499fb211db97%7D/components/componentCollectorService.js :: anonymous :: line 1155" data: no]
[Break on this error] obj = getIface(request.loadGroup.groupObserver);
The thing is visible at this location: Dynamics Photo
Thanks in advance!!
I get this error when I'm using page speed - extension to firebug. If you use the same try to deactivate this extension.
disabling page speed did not helped... so uninstalled the extension.. and it works

Resources