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)
Related
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;
}, []);
I have been trying to store Audio file in persistent storage for two days without success.
So far I am able to create an audio file which records audio from Microphone (The app has the permission) using the code attached below.
The audio file is getting generated & stored successfully, I can play it.
But the real problem is when I close the app and come back and try to play the file it shows error.
"{"message": "Cannot use audio file from resource '/myrecording.wav'",
"code":1}"
The file is not persistent across app sessions even though I used LocalFileSystem.PERSISTENT.
I am not sure whether the problem is with my Media/Audio code or File storage code.
Please find the code attached below:
Below function records the audio from the microphone.
function _recordAudio() {
var deferred = $q.defer();
var src = "myrecording.wav";
alert("SRC:" + src);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(src, {
create: true,
exclusive: false
}, function (fileEntry) {
alert("File " + src + " created at " + fileEntry.fullPath);
var mediaRec = new Media(fileEntry.fullPath,
function () {
alert("Success");
}, function (error) {
alert("error:" + JSON.stringify(error));
});
// Record audio
mediaRec.startRecord();
// Stop recording after 10 sec
var recTime = 0;
var recInterval = setInterval(function () {
recTime = recTime + 1;
if (recTime >= 5) {
clearInterval(recInterval);
mediaRec.stopRecord();
deferred.resolve(fileEntry.fullPath);
}
}, 1000);
}, function (error) {
alert("getFile error:" + JSON.stringify(error));
deferred.reject();
}); //of getFile
}, function (error) {
alert("requestFileSystem error:" + JSON.stringify(error));
deferred.reject();
}); //of requestFileSystem
return deferred.promise;
}
Below function plays the audio.
function _play2() {
var src = "myrecording.wav";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(src, null, function (fileEntry) {
alert("File " + src + " created at " + fileEntry.fullPath);
var mediaRec = new Media(fileEntry.fullPath,
function () {
alert("Success play2");
}, function (error) {
//Getting error after closing and opening the app
//Error message = {"message": "Cannot use audio file from resource '/myrecording.wav'","code":1}
alert("error play2:" + JSON.stringify(error));
});
mediaRec.play();
});
});
}
I solved this problem by passing cdvfile: path to the Media plugin in PlayAudio function code and copying the file from Temp storage to persistent storage.
I had to use localURL of the file.
This part solved my problem:
fileEntry.file(function (file) {
_playNow(file.localURL);
}
For full functions refer code snippets below:
recordAudio: function (projectNo, ItemNo) {
try {
var deferred = $q.defer();
var recordingTime = 0;
_audioLoader = $("#audioLoader");
_audioLoader.show();
UtilityService.showPopup('audio');
_isRecording = true;
_recordFileName = "Audio_" + projectNo + "_" + ItemNo + ".wav";
_mediaRecord = new Media(_recordFileName);
//Record audio
_mediaRecord.startRecord();
var recordingInterval = setInterval(function () {
recordingTime = recordingTime + 1;
$('#audioPosition').text(_secondsToHms(recordingTime));
if (!_isRecording) {
clearInterval(recordingInterval);
_mediaRecord.stopRecord();
_mediaRecord.release();
deferred.resolve();
}
}, 1000);
//document.getElementById('audioPosition').innerHTML = '0 sec';
$('#audioPosition').text('0 sec');
return deferred.promise;
}
catch (ex) {
alert('WMMCPA|recordAudio:- ' + ex.message);
}
},
Get file path from the persistent storage and send it to the play method.
//To play recorded audio for specific project item
playAudio: function (projectNo, ItemNo) {
try {
_recordFileName = "Audio_" + projectNo + "_" + ItemNo + ".wav";
var newFileUri = cordova.file.dataDirectory + _recordFileName;
window.resolveLocalFileSystemURL(newFileUri, function (fileEntry) {
fileEntry.file(function (file) {
_playNow(file.localURL);
}, function (error) {
alert("WMMCPA|playAudio.file:-" + JSON.stringify(error));
});
}, function (error) {
alert("WMMCPA|playAudio.resolveLocalFileSystemURL:-" + JSON.stringify(error));
});
}
catch (ex) {
alert("WMMCPA|playAudio:-" + ex.message);
}
}
function _playNow(src) {
try {
var mediaTimer = null;
_audioLoader = $("#audioLoader");
_audioLoader.show();
UtilityService.showPopup('audio');
//Create Media object from src
_mediaRecord = new Media(src);
//Play audio
_mediaRecord.play();
} catch (ex) {
alert('WMMCPA|_playNow.mediaTimer:- ' + ex.message);
}
}, 1000);
} catch (ex) {
alert('WMMCPA|_playNow:- ' + ex.message);
I'm currently trying to make push notification working for dev/production environment through Appcelerator Platform.
I created my push certificates (dev/prod) on apple developer platform, I exported it to .p12 file, and uploaded it on my ArrowDB iOS Push configuration. My Titanium app and my ArrowDB seems correctly linked (good keys for production and developpement).
From my app, I get device token, I get a successfull return from subscribing to notifications, and I can see from Appcelerator that I have one ios device linked.
When I send push notification from Appcelerator ArrowDB platform, I don't receive anything while Appcelerator logs shows a Successful push.
My code for ACS Notification handling :
var Cloud = require('ti.cloud');
var ANDROID = Ti.Platform.name === 'android';
var IOS = !ANDROID && (Ti.Platform.name === 'iPhone OS');
var BLACKBERRY = !ANDROID && !IOS && (Ti.Platform.name === 'blackberry');
Cloud.debug = true; // optional; if you add this line, set it to false for production
var deviceToken = null;
// Check if the device is running iOS 8 or later
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
Ti.Network.registerForPushNotifications({
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
});
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types: [
Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
]
});
}
// For iOS 7 and earlier
else {
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types: [
Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND
],
success: deviceTokenSuccess,
error: deviceTokenError,
callback: receivePush
});
}
// Process incoming push notifications
function receivePush(e) {
console.log('Received push: ' + JSON.stringify(e));
alert('Received push: ' + JSON.stringify(e));
}
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
deviceToken = e.deviceToken;
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
function ACSPush(acsuid, acspwd) {
this.acsuid = acsuid || false;
this.acspwd = acspwd || false;
}
ACSPush.prototype.registerDevice = function(channel_name, onReceive, onLaunched, onFocused, androidOptions, iosOptions, blackberryOptions) {
var that = this,
token = '';
function deviceTokenSuccess(e) {
console.log('Device Token: ' + e.deviceToken);
token = e.deviceToken;
that.token = token;
loginToACS(that.acsuid, that.acspwd, token, channel_name);
}
function deviceTokenError(e) {
console.log('Token Error: ' + e.error);
}
function receivePush(e) {
onReceive(e.data);
console.log("push notification received: " + JSON.stringify(e.data));
}
if (ANDROID) {
var CloudPush = require('ti.cloudpush');
CloudPush.retrieveDeviceToken({
success : deviceTokenSuccess,
error : deviceTokenError
});
CloudPush.focusAppOnPush = androidOptions.focusAppOnPush || false;
CloudPush.showAppOnTrayClick = androidOptions.showAppOnTrayClick || false;
CloudPush.showTrayNotification = androidOptions.showTrayNotification || false;
CloudPush.showTrayNotificationsWhenFocused = androidOptions.showTrayNotificationsWhenFocused || false;
CloudPush.singleCallback = androidOptions.singleCallback || true;
CloudPush.addEventListener('callback', onReceive);
CloudPush.addEventListener('trayClickLaunchedApp', onLaunched);
CloudPush.addEventListener('trayClickFocusedApp', onFocused);
} else if (IOS) {
// Check if the device is running iOS 8 or later
if (parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
function registerForPush() {
Ti.Network.registerForPushNotifications({
success : deviceTokenSuccess,
error : deviceTokenError,
callback : receivePush
});
// Remove event listener once registered for push notifications
Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush);
};
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', registerForPush);
// Register notification types to use
Ti.App.iOS.registerUserNotificationSettings({
types : iosOptions.types,
categories : iosOptions.categories
});
} else {
// For iOS 7 and earlier
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types : iosOptions.types,
success : deviceTokenSuccess,
error : deviceTokenError,
callback : receivePush
});
}
} else if (BLACKBERRY) {
Ti.BlackBerry.createPushService({
appId : blackberryOptions.appId,
ppgUrl : blackberryOptions.ppgUrl,
usePublicPpg : blackberryOptions.usePublicPpg,
launchApplicationOnPush : blackberryOptions.launchApplicationOnPush,
onSessionCreated : function(e) {
console.log('Session Created');
},
onChannelCreated : function(e) {
console.log('Channel Created\nMessage: ' + e.message + '\nToken: ' + e.token);
token = e.token;
that.token = token;
console.log("Device Token: " + token);
loginToACS(that.acsuid, that.acspwd, token, channel_name);
},
onPushReceived : function(e) {
onReceive(e.data);
e.source.removeAllPushes();
},
onConfigError : function(e) {
console.log('ERROR\nTitle: ' + e.errorTitle + +'\nMsg: ' + e.errorMessage);
},
onError : function(e) {
console.log('ERROR\nTitle: ' + e.errorTitle + +'\nMsg: ' + e.errorMessage);
},
onAppOpened : function(e) {
onLaunched(e.data);
e.source.removePush(e.pushId);
}
});
} else {
alert("Push notification not implemented yet into acspushmod for " + Ti.Platform.osname);
}
};
ACSPush.prototype.unsubscribeFromChannel = function(channel_name, token, onSuccess, onFail) {
var that = this;
Cloud.PushNotifications.unsubscribe({
channel : channel_name,
device_token : token
}, function(e) {
if (e.success) {
onSuccess(e);
} else {
onFail(e);
}
});
};
ACSPush.prototype.getToken = function() {
return this.token;
};
function loginToACS(acsuid, acspwd, token, channel_name) {
if (!acsuid && !acspwd) {
console.log("loginToACS -> subscribe as guest");
subscribeForPushNotifications(token, channel_name, true);
return;
}
Cloud.Users.login({
login : acsuid,
password : acspwd
}, function(e) {
if (e.success) {
var user = e.users[0];
console.log("loginToACS -> Status: Successful");
subscribeForPushNotifications(token, channel_name);
} else {
console.log('acsuid = ' + acsuid + " acspwd = " + acspwd);
console.log("loginToACS -> Error :" + e.message);
}
});
};
function subscribeForPushNotifications(token, channel_name, subscribeAsGuest) {
var prams = {
channel : channel_name,
type : IOS ? 'ios' : Ti.Platform.osname, // osname return iphone / ipad on iOS
device_token : token
};
var callBack = function(e) {
if (e.success) {
console.log('subscribeForPushNotifications -> Status: Successful [' + channel_name + ']');
} else {
console.log('subscribeForPushNotifications -> Error ' + token + '(subscribeToServerPush) :\\n' + ((e.error && e.message) || JSON.stringify(e)));
}
};
if (subscribeAsGuest) {
Cloud.PushNotifications.subscribeToken(prams, callBack);
} else {
Cloud.PushNotifications.subscribe(prams, callBack);
}
};
And This code used to work before I change appcelerator account (migrating to my client account).
If you guys have any idea of what am I doing wrong, I will be very thankful.
Thanks a lot !
Environment : Appcelerator studio, Titanium SDK 5.0.0.GA, iphone5S
The gulp plugin gulp-ruby-sass doesn't work "gulp-ruby-sass": "^2.0.4" for the compiler at the same time it does work with its own old version "gulp-ruby-sass": "^0.7.1"
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
notify = require("gulp-notify"),
bower = require('gulp-bower');
var config = {
sassPath: './resources/sass',
bowerDir: './bower_components'
};
gulp.task('css', function () {
return gulp.src(config.sassPath + '/style.scss')
.pipe(sass({
loadPath: [
'./resources/sass',
config.bowerDir + '/bootstrap-sass/assets/stylesheets',
config.bowerDir + '/font-awesome/scss', ]
})
.on("error", notify.onError(function (error) {
return "Error: " + error.message;
})))
.pipe(gulp.dest('./public/css'));
});
The code was for old version of gulp-ruby-sass, new version 2.0.4 required another way for coding
gulp.task('css', function () {
return sass(config.sassPath + '/style.scss', {
precision: 6,
stopOnError: true,
cacheLocation: './',
loadPath: [
'./resources/sass',
config.bowerDir + '/bootstrap-sass/assets/stylesheets',
config.bowerDir + '/font-awesome/scss', ]
})
.on("error", notify.onError(function (error) {
return "Error: " + error.message;
}))
.pipe(gulp.dest('./public/css'));
});
Using phonegap build for iOS platform, the download procedure is not working!
Could someone tell me why the code below returned errors messages:
("download error source " + error.source);
could not download the image from online
// e.g: http://www.sushikoapp.com/img/branches/thumbs/big_sushiko-bchamoun.jpg
("upload error code" + error.code); sometimes 1 and sometimes 3
The code is below:
var ios_directoryEntry = fileSystem.root;
ios_directoryEntry.getDirectory("branches", { create: true, exclusive: false }, onDirectorySuccessiOS, onDirectoryFailiOS);
var ios_rootdir = fileSystem.root;
//var ios_fp = ios_rootdir.fullPath;
var ios_fp = ios_rootdir.toURL();
ios_fp = ios_fp + "branches/" ;
//ios_fp = "cdvfile://localhost/persistent/branches/";
var fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI(imgURL + "branches/thumbs/big_sushiko-bchamoun.jpg" ), ios_fp + "big_big_sushiko-bchamoun.jpg",
function (entry) {
alert("download complete: " + entry.fullPath);
}
},
function (error) {
//Download abort errors or download failed errors
alert("download error source " + error.source);
alert("upload error code" + error.code);
}
);
Thank you for your suggestion...
The problem is you're treating the file API operations as synchronous, when they're actually asynchronous.
You can use cordova.file to reference the target folder on the filesystem (see here: https://github.com/apache/cordova-plugin-file/blob/master/doc/index.md).
So try something like this:
resolveLocalFileSystemURL(cordova.file.documentsDirectory, onGetDocuments, function(error) {
console.error("Error getting Documents directory: "+error.code);
});
function onGetDocuments(entry) {
console.log("Got Documents directory");
entry.getDirectory("branches", { create: true, exclusive: false }, onGetBranches, function(error) {
console.error("Error creating/getting branches directory: "+error.code);
});
}
function onGetBranches(entry){
console.log("Got branches directory");
doFileTransfer(entry.toURL());
}
function doFileTransfer(ios_fp){
var fileTransfer = new FileTransfer();
fileTransfer.download(encodeURI(imgURL + "branches/thumbs/big_sushiko-bchamoun.jpg" ), ios_fp + "big_big_sushiko-bchamoun.jpg",
function (entry) {
alert("download complete: " + entry.fullPath);
}
},
function (error) {
//Download abort errors or download failed errors
alert("download error source " + error.source);
alert("upload error code" + error.code);
}
);
}
You are trying to write a file to the iOS root File system, this is not possible since all app in iOS are sandboxed and can only access their own sandbox.
So don't use fileSystem.root but fileSystem.documents.