Ionic/Cordova Social Sharing - ios

I added the plugin to my app like so: cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git
Here's my code in my controller:
$scope.OtherShare = function(){
window.plugins.socialsharing.share('myTitle',null,null,'sometingIShareHEre');
}
My code works well on my android device. But in iOS it only works after I exit the app then goes back to it. I tried adding $ionicPlatform.ready before/after button click but it didn't changed a thing? What am I missing?

This is strange, I am guessing this would be a device.ready issue. Try wrapping up your code in the device ready callback like
$scope.OtherShare = function(){
document.addEventListener("deviceready", function(){
window.plugins.socialsharing.share('myTitle',null,null,'sometingIShareHEre');
}, false);
}
In Ionic
$scope.OtherShare = function(){
ionic.Platform.ready(function(){
window.plugins.socialsharing.share('myTitle',null,null,'sometingIShareHEre');
});
}
Hope it helps

Related

Cordova : Inappbrowser breaks UI while Screen orientation changes from landscape to portrait on iOS

I am developing app using cordova 5.4.1, Also I am using latest InAppBrowser plugin. Below are the steps to reproduce the issue.
Open the URL in InAppBrowser
Change the app orientation from portrait to landscape
Press done button of InAppBrowser and check the app in landscape mode only, you will get some blank portion
I am using iOS 9.2.1
Please let me know if some one has faced same issue and got fixed.
Thank you in advance.
I know it's a bit late but I wanted to share how I fixed this in case you or anyone else is having this issue.
As noted in the issue mentioned in jcesarmobile's comment, it appears that cordova-plugin-statusbar & cordova-plugin-inappbrowser don't play nice together. The ticket status says resolved, although I'm still having this problem. To fix it you can either delete the plugin, or, if you need the plugin then you can add an event listener to hide then show it again on exit:
openUrl(url) {
let ref = cordova.InAppBrowser.open(url, '_blank', options);
ref.addEventListener('exit', () => {
StatusBar.hide();
StatusBar.show();
})
}
StatusBar.hide() is what fixes the issue.
EDIT: As noted by René in the comments of this similar issue, a blank column exists in iPad with the fix noted above. In order to completely fix the issue in both iPhone and iPad without having to remove the plugin, wrap the StatusBar.show() call inside a setTimeout of a second:
openUrl(url) {
let ref = cordova.InAppBrowser.open(url, '_blank', options);
ref.addEventListener('exit', () => {
StatusBar.hide();
setTimeout( () => {
StatusBar.show();
}, 1000)
})
}

change phone orientation but scope variable doesn't refresh

I am using cordova plugin to handle orientation. I want to change to a different view if orientation changes. So I try to define a variable in $scope and do related changes on UI. here is my code
window.addEventListener("orientationchange", function() {
$scope.orientation = screen.orientation;
});
this code snippet I referred from cordova plugin orientation homepage. but the UI doesn't have any change when orientation changes. I even got $scope.orientation undefined(I tested by ng-show)
How did this happen? Thanks for any help.
Use $apply().
angular.element($window).on("orientationchange", function() {
$scope.orientation = screen.orientation;
$scope.$apply();
});
This lets the AngularJS framework know a change has occurred.

phonegap-plugin-barcodescanner freeze on ios

I'm using ionic version 1.7.12 with the plugin phonegap-plugin-barcodescanner version 4.1.0 on OSX 10.11.2, additional node version is v0.10.26 and cordova 5.4.1 testing on IOS 6+, after my projects compile and install the ipa on the testing device when i try to open the scanner it freeze the app, something to add this is a legacy app.
The estrange thing its that if i start a new project from scratch using ionic cli and and install the plugin it works just fine.
Any place where i should look or what im doing wrong.
Thanks
What do you mean by "freeze"? i have similar problem, when i toggle bar code scanner with a button clicked, it open up a camera view and freeze, and by "freeze" i mean a image toked by the camera and not moving(you can still click cancel button and return back to the view).
i found out the button click event has toggle twice with one click and it explained why you have a image not moving.
i solved this problem by working around.
$scope.scannerActive = false;
$scope.scanBarcode = function() {
if(!$scope.scannerActive) {
$scope.scannerActive = true;
$ionicPlatform.ready(function() {
$cordovaBarcodeScanner.scan().then(
function(result) {
if (!result.cancelled) {
console.log(result)
}
else {
console.log('cancelled')
}
},function(error) {
alert(JSON.stringify(error));
}).finally(function() {
$scope.scannerActive = false;
});
});
}
};

PushPlugin Not Asking for Permissions on iOS

I'm working on setting up Push Notifications for an iOS app using the Ionic Framework but I'm running into a problem.
I added the plugin using the following
ionic plugin add https://github.com/phonegap-build/PushPlugin.git
and then added the following to my services.js file:
window.onNotificationAPN = function(event){
alert(event);
}
angular.module('starter.services', [])
.run(function($ionicPlatform){
$ionicPlatform.ready(function($scope, $window){
var tokenHandler = function(result){
alert('tokenHandler' + result);
}
var errorHandler = function(error){
alert('errohandler' + error);
}
var pushNot = window.plugins.pushNotification;
pushNot.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
}
);
});
})
When I run the app on my test device (running iOS 6.1.6) using command+R or sending it using testflight the application runs but never asks for permission to send push notifications and the the tokenHandler function is never called. Any help would be greatly appreciated.
Thanks for asking the question. I was searching for this for hours.
Turns out the solution for me was making sure that the opening angular module line in the app.js file included the ionic.service.core module dependency.
Then everything worked.
NOTE: (i wish it had thrown an error instead of allowing the push.register call to actually return a token)
angular.module('starter', ['ionic', 'ionic.service.core'])
The way I was able to solve this was to switch over to using ngCordova's Push script with the PushPlugin.

Open a local pdf file with cordova

Im using cordova 3.3.0 and i would like to open a local pdf file and then close it on user demand.
ref = window.open(encodeURI(path), '_blank', 'location=yes');
ref.addEventListener('exit', function() {
ref.removeEventListener('exit', function(){});
ref.close();
} );
This opens a file in inapp browser but i cannot get back to the actual app when I open some pdf file. How to add some close button or something ?
Im trying to get this working on ios.
Long time since you asked this but just had exactly the same issue. I had to install the inAppBrowser plugin on my project and the Done button appeared. Without the plugin installed, the pdf opened but the Done button was not shown.
What you have should work. On iOS a "Done" button should appear in the lower left of the screen.
function openPDF(){
ref = window.open('http://static.googleusercontent.com/media/www.google.com/en/us/webmasters/docs/search-engine-optimization-starter-guide.pdf', '_blank', 'location=yes');
ref.addEventListener('exit', function() {
ref.removeEventListener('exit', function(){});
ref.close();
} );
}
I tested on iOS 6.1 and iOS 7. Of course you can set location=no to remove the URL at the bottom.

Resources