I am very beginner in developing ionic apps and trying to integrate in-app-purchase2 plugin in ionic 3 for ios. Everytime my code stop and gives error this.store.when(productId).approved( (product: IAPProduct) => {}) is not a function.
This is my try that i do till now:
configurePurchasing() {
let productId;
try {
if (this.platform.is('ios')) {
productId = this.product.appleProductId;
} else if (this.platform.is('android')) {
productId = this.product.googleProductId;
}
// Register Product
// Set Debug High
this.store.verbosity = this.store.DEBUG;
// Register the product with the store
this.store.register({
id: productId,
alias: productId,
type: this.store.CONSUMABLE
});
this.registerHandlers(productId);
this.store.ready().then((status) => {
console.log(JSON.stringify(this.store.get(productId)));
console.warn('Store is Ready: ' + JSON.stringify(status));
console.warn('Products: ' + JSON.stringify(this.store.products));
});
// Errors On The Specific Product
this.store.when(productId).error( (error) => {
alert('An Error Occured' + JSON.stringify(error));
});
// Refresh Always
console.log('Refresh Store');
this.store.refresh();
} catch (err) {
console.warn('Error On Store Issues' + JSON.stringify(err));
}
}
registerHandlers(productId) {
// Handlers
this.store.when(productId).approved( (product: IAPProduct) => {
// Purchase was approved
product.finish();
});
this.store.when(productId).registered( (product: IAPProduct) => {
console.warn('Registered: ' + JSON.stringify(product));
});
this.store.when(productId).updated( (product: IAPProduct) => {
console.warn('Loaded' + JSON.stringify(product));
});
this.store.when(productId).cancelled( (product) => {
alert('Purchase was Cancelled');
});
// Overall Store Error
this.store.error( (err) => {
alert('Store Error ' + JSON.stringify(err));
});
}
async purchase() {
let productId;
if (this.platform.is('ios')) {
productId = this.product.appleProductId;
} else if (this.platform.is('android')) {
productId = this.product.googleProductId;
}
console.log('Products: ' + JSON.stringify(this.store.products));
console.log('Ordering From Store: ' + productId);
try {
let product = this.store.get(productId);
alert('Product Info: ' + JSON.stringify(product));
// let order = await this.store.order(productId);
// alert('Finished Purchase');
} catch (err) {
console.log('Error Ordering ' + JSON.stringify(err));
}
}
From last 8 hours i am stuck at this point. Anyone here help me out in integrating this plugin. If you have any good tutorial related to this please post in comments. Thanks in advance.
Related
I am using this plugin (https://github.com/j3k0/cordova-plugin-purchase) to handle a in app subscription.
iap.validator = "https://validator.fovea.cc/v1/validate?appName=XXX";
//initiate initInAppPurchase function
useEffect(() => {
const init = async () => {
await initInAppPurchase();
}
init();
}, []);
//if on an ios or android device, then get product info
const initInAppPurchase = () => {
if ((isPlatform('ios')) || (isPlatform('android'))) {
iap.verbosity = iap.DEBUG;
iap.register({
id: "tpmonthly",
alias: "Monthly",
type: iap.PAID_SUBSCRIPTION
});
iap.ready(() => {
let product = iap.get('Monthly');
setPrice(product.price)
setProduct(product)
})
iap.refresh();
}
}
//if user clicks purchase button
const purchaseProduct = () => {
if (product.owned) {
alert('A subscription is currently active.')
} else {
iap.order('Monthly').then(() => {
iap.when("tpmonthly").approved((p: IAPProduct) => {
p.verify();
});
iap.when("tpmonthly").verified((p: IAPProduct) => {
p.finish();
history.push("/ios-signup/");
});
})
}
}
return (
<Button size="large" variant="outlined" onClick={purchaseProduct}>Subscribe Monthly for {productPrice}</Button>
);
What I am hoping to get is that once the subscription is verified that it then redirects the app to /ios-signup/ .. this is not happening.
Is this code correct? And why would it not redirect after p.finish?
I'm using react-native-fbsdk {ShareDialog} to post my feeds on Facebook but ShareDialog is not returning the post Id it's always null in my case.
My Import
import { ShareDialog, LoginManager, AccessToken, LoginButton } from "react-native-fbsdk";
This is my code
const shareLinkContent = {
contentType: 'link',
contentUrl: 'https://www.niofox.com/',
contentDescription: 'Test Sharing Description'
};
var tmp = this;
ShareDialog.canShow(shareLinkContent).then(
(canShow) => {
if (canShow) {
return ShareDialog.show(shareLinkContent);
}
}
).then(
(result) => {
if (result.isCancelled) {
alert('Share cancelled');
} else {
alert('Share success with postId: ' + JSON.stringify(result));
}
},
(error) => {
alert('Share fail with error: ' + error);
}
);
I'm using "electron-updater" to check for auto-updating Electron application.
Calling "checkForUpdatesAndNotify()" function.
In a console, I get "Skip checkForUpdatesAndNotify because application is not packed".
mac0S Mojave,
"electron-updater": "^4.0.6",
"electron": "^3.0.13",
"electron-builder": "20.28.1"
const {autoUpdater} = require("electron-updater");
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.on('checking-for-update', () => {
console.log('Checking for update...');
});
autoUpdater.on('update-available', (info) => {
console.log('Update available.');
});
autoUpdater.on('update-not-available', (info) => {
console.log('Update not available.');
});
autoUpdater.on('error', (err) => {
console.log('Error in auto-updater. ' + err);
});
autoUpdater.on('download-progress', (progressObj) => {
let log_message = "Download speed: " + progressObj.bytesPerSecond;
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
console.log(log_message);
});
autoUpdater.on('update-downloaded', (info) => {
console.log('Update downloaded');
});
checkForUpdatesAndNotify() just won't work in development mode.
If you insist on test it in dev mode, you can do some hack with isPackaged:
const app = require('electron').app;
Object.defineProperty(app, 'isPackaged', {
get() {
return true;
}
});
Be careful, do not use this hack for production, it may
use autoUpdater.checkForUpdates instead
I'm using the sqs-consumer node module package.
I have the following code:
init: function () {
var app = Consumer.create({
queueUrl: Settings.getSetting("sendgrid-aws-sqs-queue"),
batchSize: 1,
visibilityTimeout: 30,
waitTimeSeconds: 20,
sqs: MarvelAWS.sqs,
handleMessage: function (message, done) {
try {
var msgBody;
try {
msgBody = JSON.parse(message.Body);
} catch (err) {
msgBody = null;
this._warn("parsing error handling SQS queue " + err, msgBody);
}
var environment = Settings.getSetting('environment');
if (validateMsg(msgBody) && (environment !== "prod" || this.LIST_TO_ID[msgBody.listId.toString()])) {
var userProfile = msgBody.profile,
timeSent = msgBody.timeSent,
action = msgBody.action,
listId = msgBody.listId.toString(),
suppressionListId = msgBody.suppressionListId.toString();
_.each(this.actionsMap[action], function (oneAction) {
this._debug(oneAction + ':' + listId + ' ' + msgBody.profile.email);
sendgridQueueManager.createQueue({
action: oneAction
});
sendgridQueueManager.push({
action: oneAction,
listId: listId,
suppressionListId: suppressionListId,
timeSent: timeSent,
profile: userProfile
});
}.bind(this));
EngineMonitor.countOperation(EngineMonitor.OPS.SENDGRID_SQS_QUEUE_PULL_SUCCESS);
} else {
this._warn("validation error", msgBody);
EngineMonitor.countOperation(EngineMonitor.OPS.SENDGRID_SQS_QUEUE_PULL_ERROR);
}
done();
} catch (err) {
this._warn("error_processing_message " + err);
done(new Error('error processing message'));
}
}.bind(this)
});
app.on("message_received", function () {
this._debug("message_received");
EngineMonitor.countOperation(EngineMonitor.OPS.SENDGRID_SQS_QUEUE_MESSAGE_RECEIVED);
}.bind(this));
app.on("message_processed", function () {
this._debug("message_processed");
EngineMonitor.countOperation(EngineMonitor.OPS.SENDGRID_SQS_QUEUE_MESSAGE_PROCESSED);
}.bind(this));
app.on("error", function (err, message) {
this._warn("message_error " + err + " " + message);
EngineMonitor.countOperation(EngineMonitor.OPS.SENDGRID_SQS_QUEUE_PULL_ERROR);
}.bind(this));
app.on("processing_error", function (err, message) {
this._warn("processing_error " + err);
EngineMonitor.countOperation(EngineMonitor.OPS.SENDGRID_SQS_QUEUE_PULL_ERROR);
}.bind(this));
app.start();
this._debug('sqs_app_start');
},
sometimes a message gets added to the SQS queue but doesn't not get received by the consumer/
Here are my sqs queue settings:
Can someone please help?
In what cases do a message get added to the Queue and not received by the consumer?
Hello I am attempting to access the user photo album on iOS in order for users to select a profile pic in my app.
I am using native script and I cannot figure out how to request permission to do so. My error is:
CONSOLE LOG file:///app/shared/user-view-model/user-view-model.js:96:28: fileUri: file:///var/mobile/Media/DCIM/100APPLE/IMG_0002.JPG
CONSOLE LOG file:///app/shared/user-view-model/user-view-model.js:101:24: NSErrorWrapper: You don’t have permission to save the file “100APPLE” in the folder “DCIM”.
I used
<key>NSPhotoLibraryUsageDescription</key>
<string> ${PRODUCT_NAME} photo use</string>
in my info.plist but no luck. Does anybody know what I'm missing?
var frame = require("ui/frame");
var platform = require("platform");
var firebase = require("nativescript-plugin-firebase");
var page;
var list;
function pageLoaded(args) {
page = args.object;
list = page.getViewById("urls-list");
}
exports.pageLoaded = pageLoaded;
function onSelectMultipleTap(args) {
var imagepicker = require("nativescript-imagepicker");
var context = imagepicker.create({
mode: "multiple"
});
startSelection(context);
}
exports.onSelectMultipleTap = onSelectMultipleTap;
function onSelectSingleTap(args) {
var imagepicker = require("nativescript-imagepicker");
var context = imagepicker.create({
mode: "single"
});
startSelection(context);
}
exports.onSelectSingleTap = onSelectSingleTap;
function startSelection(context) {
context
.authorize()
.then(function() {
list.items = [];
return context.present();
})
.then(function(selection) {
console.log("Selection done:");
selection.forEach(function(selected) {
console.log("----------------");
console.log("uri: " + selected.uri);
console.log("fileUri: " + selected.fileUri);
uploadImage(selected.fileUri);
});
list.items = selection;
}).catch(function (e) {
console.log(e);
});
}
function uploadImage(imageUrl){
firebase.uploadFile({
remoteFullPath: "test/testimage.jpg",
localFullPath: imageUrl,
onProgress: function(status) {
console.log("Uploaded fraction: " + status.fractionCompleted);
console.log("Percentage complete: " + status.percentageCompleted);
}
}).then((success) => {
console.log("success: " + success);
}, (error) => {
console.log("Error: " + error);
})
}
You need this requestAuthorization
PHPhotoLibrary.requestAuthorization(function (result) {
if (result === PHAuthorizationStatus.PHAuthorizationStatusAuthorized) {
// OK
} else {
// no permissions!
}
});
You also need this in your info.plist
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string></string>
</dict>
I found a solution from this github post
https://github.com/NativeScript/sample-ImageUpload/issues/2#issuecomment-252795778
The solution was to use the getImage() method and then saveToFile method on the result.
private selectImage(context){
context.authorize()
.then(() => {return context.present()})
.then((selection) => {
selection.forEach((selected) => {
selected.getImage()
.then((imageSource) => {
var appPath = fs.knownFolders.currentApp().path;
var profilePath = "/img/profile.jpg";
var filePath = fs.path.join(appPath, profilePath);
var saved = imageSource.saveToFile(filePath, enums.ImageFormat.jpeg);
console.log(`item saved:${saved}`);
console.log("FilePath: " + filePath);
console.log("Image source " + JSON.stringify(imageSource));
},
(error) => {
console.log("error");
})
})
})
}