iOS6: Twitter SetInitialText Not Working - ios

I have just updated my application to iOS 6, and the SetInitialText function of the TWTweetComposeViewController has stopped working. The composer just comes up empty. I am using MonoTouch, has anyone else seen this issue? The same code still works fine on my iOS 5 device.

This works as expected for me with the following code:
var button2 = UIButton.FromType (UIButtonType.RoundedRect);
button2.Frame = new RectangleF (0f, 0f, 300f, 40f);
button2.SetTitle ("Tweet!", UIControlState.Normal);
button2.TouchUpInside += (sender, e) => {
var tvc = new TWTweetComposeViewController ();
tvc.SetInitialText ("Here is a tweet...");
tvc.SetCompletionHandler ((result) => {
if (result == TWTweetComposeViewControllerResult.Cancelled) {
Console.WriteLine ("Cancelled sending the tweet!");
} else {
Console.WriteLine ("Tweet sent! hurrah!");
}
this.DismissModalViewControllerAnimated (true);
});
this.PresentModalViewController (tvc, true);
};
View.AddSubview (button2);
Even though PresentModal and DismissModal are deprecated, do you have any example code of the problem?

Related

Xamarin.Forms ZXing.Net.Mobile loosing current page after scan result on iOS 10

I'm using Xamarin.Forms and I have implemented ZXing.Net.Mobile for scanning bar codes.
On Android it's working fine, on iOS 10 after reading a barcode the function "OnScanResult" is fired and executes the command Navigation.PopAsync() which closes the scanning page but after a second it closes also the current page where I have displayed the result !
MyTapScan.Tapped += async (sender, e) =>
{
await MyBtScan.ScaleTo(1.20, 100, Easing.Linear);
await MyBtScan.ScaleTo(1, 100, Easing.Linear);
await Task.Delay(50);
//--------------------------------------------
MyAppLib.MyAppUtilitiesBarCodeReader MyBarCodeReader = new MyAppLib.MyAppUtilitiesBarCodeReader();
var MyScannerPage = MyBarCodeReader.GetBarCodeReaderPage();
//--------------------------------------------
MyScannerPage.OnScanResult += (result) => {
//Stop scanning
MyScannerPage.IsScanning = false;
//Pop the page and show the result
Device.BeginInvokeOnMainThread(() => {
Navigation.PopAsync();
MyMachSerialNumber.Text = result.Text;
});
};
//--------------------------------------------
//Display scanner
await Navigation.PushAsync(MyScannerPage);
};
Please please help..!! :)
Every time MyTapScan.Tapped is called you are subscribing to MyScannerPage.OnScanResult so if you tap button 5 times your OnScanResult will be called 5 times. I hope now you know how to solve that.
One of possible solutions:
Take your OnScanResult delegate and make it separate function, let say ScanFinished. Then instead of
MyScannerPage.OnScanResult += (result)
do
MyScannerPage.OnScanResult -= ScanFinished;
MyScannerPage.OnScanResult += ScanFinished;
Then you can be sure the event unsubscribed before you subscribe to it again
I have introduced a new variable to check if the scanning was already fired and now it's working fine and as expected.
This is the code:
MyTapScan.Tapped += async (sender, e) =>
{
await MyBtScan.ScaleTo(1.20, 100, Easing.Linear);
await MyBtScan.ScaleTo(1, 100, Easing.Linear);
await Task.Delay(50);
bool MyIsScanning = true;
//--------------------------------------------
MyAppLib.MyAppUtilitiesBarCodeReader MyBarCodeReader = new MyAppLib.MyAppUtilitiesBarCodeReader();
var MyScannerPage = MyBarCodeReader.GetBarCodeReaderPage();
//--------------------------------------------
MyScannerPage.OnScanResult += (result) => {
//Stop scanning
MyScannerPage.IsScanning = false;
//Pop the page and show the result
Device.BeginInvokeOnMainThread(() => {
if (MyIsScanning == true)
{
MyIsScanning = false;
MyMachSerialNumber.Text = result.Text;
Navigation.PopAsync();
}
});
};
//--------------------------------------------
//Display scanner
await Navigation.PushAsync(MyScannerPage);
};

Xamarin.iOS ZXing.Net.Mobile barcode scanner

I'm trying to add barcode scanner feature to my xamarin.ios app. I'm developing from visual studio and I've added the Zxing.Net.Mobile component from xamarin components store.
I've implemented it as shown in the samples:
ScanButton.TouchUpInside += async (sender, e) => {
//var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
//options.AutoRotate = false;
//options.PossibleFormats = new List<ZXing.BarcodeFormat>() {
// ZXing.BarcodeFormat.EAN_8, ZXing.BarcodeFormat.EAN_13
//};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
//scanner.TopText = "Hold camera up to barcode to scan";
//scanner.BottomText = "Barcode will automatically scan";
//scanner.UseCustomOverlay = false;
scanner.FlashButtonText = "Flash";
scanner.CancelButtonText = "Cancel";
scanner.Torch(true);
scanner.AutoFocus();
var result = await scanner.Scan(true);
HandleScanResult(result);
};
void HandleScanResult(ZXing.Result result)
{
if (result != null && !string.IsNullOrEmpty(result.Text))
TextField.Text = result.Text;
}
The problem is that when I tap the scan button, the capture view is shown correctly but if I try to capture a barcode nothing happens and it seems the scanner doesn't recognize any barcode.
Someone has experienced this issue? How can I made it work?
Thanks in advance for your help!
I answered a similar question here. I couldn't get barcodes to scan because the default camera resolution was set too low. The specific implementation for this case would be:
ScanButton.TouchUpInside += async (sender, e) => {
var options = new ZXing.Mobile.MobileBarcodeScanningOptions {
CameraResolutionSelector = HandleCameraResolutionSelectorDelegate
};
var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
.
.
.
scanner.AutoFocus();
//call scan with options created above
var result = await scanner.Scan(options, true);
HandleScanResult(result);
};
And then the definition for HandleCameraResolutionSelectorDelegate:
CameraResolution HandleCameraResolutionSelectorDelegate(List<CameraResolution> availableResolutions)
{
//Don't know if this will ever be null or empty
if (availableResolutions == null || availableResolutions.Count < 1)
return new CameraResolution () { Width = 800, Height = 600 };
//Debugging revealed that the last element in the list
//expresses the highest resolution. This could probably be more thorough.
return availableResolutions [availableResolutions.Count - 1];
}

Why Facebook profile picture request return null on iOS?

Everything works perfect on android but when I try to get the profile picture on iOS devices. The image returns null. I checked the Facebook documentation for iOS 9 I have exactly the same plist as shown in documentation. When I run the app in console I see "FB is log in" message but the profile pic has not shown. Can anyone help?
void Awake()
{
instance = this;
FB.Init(SetInıt, OnHideUnity);
}
public void FbLogin()
{
// This is an event trigger when the button pressed.
List<string> permissions = new List<string>();
permissions.Add("public_profile");
FB.LogInWithReadPermissions(permissions, AuthcallBack);
}
void DealWithFbMenus(bool isLoggedIn)
{
// This function is called in SetInit func in Awake.
if(isLoggedIn)
{
fbButton.SetActive(false);
profilePicture.gameObject.SetActive(true);
loggedInPlayer = true;
//FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUserName);
FB.API("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic);
}
else
fbButton.SetActive(true);
}
void DisplayProfilePic(IGraphResult result)
{
if(result.Texture != null)
{
profilePicture.sprite = Sprite.Create(result.Texture, new Rect(0,0, 128, 128), new Vector2());
}
}
It is a bug on Unity 5.2. It fixed on new version of Unity 5.3

Updating a Button control with an NSTimer in Xamarin

I have created a very basic ios project that has a single button on it with it's title text property set to "Start". I am trying to have this button count down from 15.
I have added the event handler for the button as below.
void StartButton_TouchUpInside (object sender, EventArgs ea) {
_currentCount = 15;
_timer = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.FromSeconds(1), () =>
{
if (_currentCount <= 0) {
StartButton.TitleLabel.Text = "Start";
_timer.Dispose();
} else {
string titleText = (_currentCount--).ToString ();
//Console.WriteLine(titleText);
StartButton.TitleLabel.Text = titleText;
//Console.WriteLine(StartButton.TitleLabel.Text);
//StartButton.SetNeedsDisplay();
}
});
}
So here is the strange thing. The Button changes to 15 just fine then it flashes back to "Start" then 14. Then 13 then "Start" then 12 etc... etc... etc...
Why is it doing this? And how do I prevent it from flashing back to start. Thanks in advance.
Try to use this.InvokeOnMainThread
private int counter = 0;
public override void WillActivate()
{
Console.WriteLine ("{0} will activate", this);
_timer = NSTimer.CreateRepeatingScheduledTimer(1, (timer) =>
{
this.InvokeOnMainThread(()=>{
Console.WriteLine("++++++++ NSTimer Call");
this.AlertTimeLabel.SetText(counter.ToString());
counter++;
});
});
}

Integrate Admob in iOS App which uses monogame

I am trying to do this for a few days, and still cannot make it. And I tried to find some samples but they are all on Android. Did anyone succeed to integrate admob on iOS?
I had some problems with AdMob bindings from monotouch-bindings repository. But then I switched to AlexTouch.GoogleAdMobAds bindings and them works just great. You can find sample of using AlexTouch.GoogleAdMobAds in README on Github. Is is quite simple, but if you'll need some help - feel free to ask more detailed question.
// code for admob "using AlexTouch.GoogleAdMobAds"
UIViewController vc = new UIViewController ();
UIViewController controller = UIApplication.SharedApplication.Windows [0].RootViewController;
var ad = new GADBannerView (GADAdSizeCons.SmartBannerLandscape, new PointF (0, 0))
{
AdUnitID = "ADMOB_ID",
RootViewController = vc
};
ad.Hidden = false;
ad.DidReceiveAd += delegate {
ad.Hidden = false;
ad.Frame = new System.Drawing.RectangleF (0, (int) 0, (int) (ad.Bounds.Width), (int) (ad.Bounds.Height));
Console.WriteLine ("AD Received");
};
ad.DidFailToReceiveAdWithError += delegate(object sender, GADBannerViewDidFailWithErrorEventArgs e) {
ad.Hidden = true;
Console.WriteLine (e.Error);
};
ad.WillPresentScreen += delegate {
Console.WriteLine ("showing new screen");
};
ad.WillLeaveApplication += delegate {
Console.WriteLine ("I will leave application");
};
ad.WillDismissScreen += delegate {
Console.WriteLine ("Dismissing opened screen");
};
ad.UserInteractionEnabled = true;
vc.View.AddSubview(ad);
vc.View.Frame = new System.Drawing.RectangleF(0f, 0f, (int)(ad.Bounds.Width), (int)(ad.Bounds.Height));
controller.View.AddSubview(vc.View);
Task.Factory.StartNew(() => {
while (true)
{
Console.WriteLine("Requesting Ad");
InvokeOnMainThread (delegate {
GADRequest r = new GADRequest();
ad.LoadRequest(r);
});
System.Threading.Thread.Sleep(30000);
}
});

Resources