iOS Widget Extension initial UIViewController - ios

I am adding a "Today" extension widget to my iOS app that I made with Xamarin. I am following this walkthrough:
https://developer.xamarin.com/guides/ios/platform_features/introduction_to_extensions/
The widget appears in my Notification section in the simulator, but I can't get any contents to appear in it. It won't even create the UIViewController class that I made and set as the initial controller to start with (I know because it never hits my breakpoint in the constructor). I set it as the principal class with this key as explained in the walkthrough:
Any idea why? I also get this message when I first launch the app after adding the extension:
appname may slow down your phone the developer of this app needs to update it to improve its compatibility
I made a sample project, with Xamarin, and the widget does appear in this project when deployed on the simulator, just not with the contents that I'm trying to add in the CodeViewController class:
https://drive.google.com/file/d/0B8xKHTqtwfKtY0xZN0xaejhlZmM/view?usp=sharing

To save you 2 days I spent on it here is the solution.
Don't run it on simulator. It doesn't work (at least on mine).
Don't try to hit breakpoint in VS. When you testing your extension your app is in background mode. VS will not give you to stop in debugger. To prove run any of your apps, press home and try to set breakpoint in VS. VS will hang till you bring your app to foreground.
Do not use View.Frame in DidLoad. The size of the frame there is the whole screen size, so when you put your label to center you will not see it. Use WillAppear like this
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (TodayMessage == null)
{
// Add label to view
TodayMessage = new UILabel(new CGRect(0, 0, View.Frame.Width, View.Frame.Height))
{
TextAlignment = UITextAlignment.Center,
BackgroundColor = UIColor.LightGray,
TextColor = UIColor.Black
};
// Calculate the values
var dayOfYear = DateTime.Now.DayOfYear;
var leapYearExtra = DateTime.IsLeapYear(DateTime.Now.Year) ? 1 : 0;
var daysRemaining = 365 + leapYearExtra - dayOfYear;
// Display the message
if (daysRemaining == 1)
{
TodayMessage.Text = String.Format("Today is day {0}. There is one day remaining in the year.", dayOfYear);
}
else
{
TodayMessage.Text = String.Format("Today is day {0}. There are {1} days remaining in the year.", dayOfYear, daysRemaining);
}
View.AddSubview(TodayMessage);
}
}

Related

Xcode 14 , XCUITests - Tap is not working for WebView default done button

We have started adopting a new version of Xcode 14, and we see many tests failure. Many test failures are mainly those with a web view inside the app. After trying all the different alternatives, we cannot tap on the done button; that's the default button when we open the web view in the app.
Please list the steps you took to reproduce the issue:
Our tests are trying tap on done button that's inside the web view and seeing error (default done button of browsers). We can check the existence of the button that's return true but can't tap on it . see attachment
that's Xcode 14 bug for sure. I also tested previous version of Xcode 13.4.1 and did not see any error
Any alternative way to handle the webview done button
extension XCUIApplication {
func tapCoordinate(at point: CGPoint) {
let normalized = coordinate(withNormalizedOffset: .zero)
let offset = CGVector(dx: point.x, dy: point.y)
let coordinate = normalized.withOffset(offset)
coordinate.tap()
}
}
with help from How to tap on a specific point using Xcode UITests
#Nish answer works fine, so I added a little variation to get the coordinate of the button and tap on it.
(Note: this will work on any screen/simulator size, because it is not dependent on the CGPoint being explicitly passed)
if let doneButton = app.buttons["Done"].waitAndHandleFailure(timeout: JourniTestConstants.asyncTimeout) {
let doneCoordinates = app.coordinate(withNormalizedOffset: .zero).withOffset(.init(dx: doneButton.frame.midX, dy: doneButton.frame.midY))
doneCoordinates.tap()
}

Swift: Animating a view (for in-app notifications) onto the screen for a few seconds before removing

I am attempting to do what is described perfectly here: https://github.com/bryx-inc/BRYXBanner
I want to create a banner that pops down on the screen for a few seconds before being removed (or removed when it is tapped on). The above project is great up until iOS 9. After that and with iOS 10, the banner no longer works as predicted and either shows itself without an animation for a third of a second or it doesn't show.
How can I add a view that animates onto the screen and then back off to provide a user a quick "No Internet" notification in-app. I want to avoid using the notification center.
I had a similar problem and created my own library for it: MDNotificationView
The example app on GitHub implements your idea. Here is a small snippet implementing it:
let view = MDNotificationCompactLayoutView()
view.textLabel.text = "No internet connection."
let notificationView = MDNotificationView(view: view)
notificationView.delegate = self
notificationView.show()
// MARK: - Notification View Delegate
func notificationDidShow(notificationView: MDNotificationView) {
// Hide the notification view automatically after 5 seconds.
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
notificationView.hide()
}
}

Xamarin iOS UIButton image not showing on device when testing

I am currently testing my xamarin iOS app on TestFlight with an iOS device. The app is running fine but the images in my UIButtons arent showing up at all.
Heres my button code:
_uiAttributes.myScheduleImage = UIImage.FromFile("images/myschedule.PNG");
_uiAttributes.myCareersImage = UIImage.FromFile("images/mycareer.PNG");
_uiAttributes.mySocialImage = UIImage.FromFile("images/mysocial.PNG");
_uiAttributes.FeedbackImage = UIImage.FromFile("images/feedback.PNG");
_uiAttributes.myDetailsImage = UIImage.FromFile("images/mydetails.PNG");
buttonList = new List<UIButton>
{
_uiControls.btn_MySchedule,
_uiControls.btn_MyCareer,
_uiControls.btn_MySocial,
_uiControls.btn_Feedback,
_uiControls.btn_MyDetails
};
buttonImageList = new List<UIImage>
{
_uiAttributes.myScheduleImage,
_uiAttributes.myCareersImage,
_uiAttributes.mySocialImage,
_uiAttributes.feedbackImage,
_uiAttributes.myDetailsImage
};
I pass this code through to a Draw method.
public void DrawImageButton(List<UIButton> buttonList, List<CGRect> buttonDimensionsList, List<UIImage> buttonImageList, UIView container)
{
for(int i = 0; i < buttonList.Count; i++)
{
buttonList[i].Frame = buttonDimensionsList[i];
buttonList[i].SetImage(buttonImageList[i], UIControlState.Normal);
container.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
buttonList[i].AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
container.AddSubview(buttonList[i]);
}
}
The buttons are showing up when i run it on a simulator but not my actual device.
I will attach an screenshot of my images below:
Resources/images
I have checked a number of related answers but theyre all in Xcode. I am currently using Visual Studio 2015 to develop my application.
If anyone can help or point me in the right direction that would be great.
So I have managed to fix this issue. The problem was that i never changed the Copy to Output Directory to "Copy Always" in the properties panel for each image. Also I had to state the path of the image being loaded.
_uiAttributes.myScheduleImage = UIImage.FromFile("images/myschedule.PNG");
Thanks for all the help!

Multitouch not working on iOS with robovm and libGDX when displaying banner ads

I'm having a problem with input in libGDX in the iOS backend. It happens when I have Mopub banner ads displayed. When I put my first finger on the screen, I get a touchDown event (pointer = 0) and when it comes to my second finger, nothing is triggered. BUT for some reason it works when I put my second finger near the banner area (I think it's the banner's frame that I'm hitting). When banner ads aren't displayed, everything works fine. Also everything works fine on Android.
I'd really appreciate the help to tackle this problem here.
Thanks in advance.
iOS 8.3;
roboVM 1.2.0;
gdx 1.6.0;
Here's how I load the Banner:
UIApplication application;
String id;
BANNER_SIZE = MPConstants.MOPUB_BANNER_SIZE;
id = BANNER_ID;
rootViewController = application.getKeyWindow().getRootViewController();
banner = new MPAdView(id, BANNER_SIZE);
double bannerWidth = UIScreen.getMainScreen().getBounds().getWidth();
double bannerHeight = bannerWidth / BANNER_SIZE.getWidth() * BANNER_SIZE.getHeight();
banner.setFrame(new CGRect((UIScreen.getMainScreen().getBounds().getWidth() / 2d) - (BANNER_SIZE.getWidth() * .5d), 0, bannerWidth, bannerHeight));
adViewController = new MPAdViewController(banner);
MPAdViewDelegate bannerDelegate = new MPAdViewDelegateAdapter(){
#Override
public UIViewController getViewController() {
return adViewController;
}
};
banner.setDelegate(bannerDelegate);
adViewController.getView().addSubview(banner);
rootViewController.getView().addSubview(adViewController.getView());
if(!isBannerLoaded) {
banner.loadAd();
isBannerLoaded = true;
}
Here's my didFinishLaunching method:
#Override
public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
super.didFinishLaunching(application, launchOptions);
//The 0 doesn't do anything. It was something I was trying out.
adController.loadBanner(application, 0);
rootViewController = application.getKeyWindow().getRootViewController();
application.getKeyWindow().setRootViewController(rootViewController);
application.getKeyWindow().addSubview(rootViewController.getView());
application.getKeyWindow().makeKeyAndVisible();
return false;
}
You should add this line to your adViewController
adViewController.getView().setMultipleTouchEnabled(true);

Strange behaviour of Geolocator.GetGeopositionAsync() after first launch

I'm writing Windows Phone 8 app that needs to get location of device (do not track changes, just get location). I added next code to the method OnNavigatedTo() of my start page but after launching app, the progress indicator does not hide even after 10 seconds timeout. But if I navigate to another page and then go back, everything works fine. This happens on the emulator, I don't have a real device. What am I doing wrong?
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
if(_geoPosition == null)
{
try
{
var geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
_progressIndicator = new ProgressIndicator
{
IsIndeterminate = true,
Text = "Getting current location, please wait...",
IsVisible = true
};
SystemTray.SetIsVisible(this, true);
SystemTray.SetProgressIndicator(this, _progressIndicator);
_geoPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
_progressIndicator.IsVisible = false;
SystemTray.SetIsVisible(this, false);
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings");
}
}
}
Thanks!
UPD: just tried to add this code to empty project and it works fine. Tried to comment out some parts of OnNavigatedTo that I did not include to the snippet and found out that the reason somewhere in initialization of data source for this page. I'm sorry for false alarm.
Your code works fine for me, try the classic restart VS and the projecy!
The code should work, tested it with an emulator and a device (nokia 820).
Best of luck

Resources