Canadian Classifieds Alerter for iOS usage update

Effective right now, I will be extending the frequency of checks from the five-ish minutes that users experience now to 12-ish minutes. You will still have your six standard alerts.

I will be offering a pro service to get 45 second checks AND extend the amount of alerts you’re allowed to have to 15 for $65 a month. Please contact me for this service!

Other not as fast but maybe just as good for you plans are:

$40 for every two minutes

$20 for every five

The people interested in this service will be people who make a lot of money off Kijiji, I realize it’s not for everyone.

Why? Are you selling out?

Sort of.

But hear me out… how much money do you think this app makes a month in ad revenue?

$150? $100?

Five bucks.

I make five bucks a month.

This app took 5 months to make as I had to learn how to program for iOS, and I get five bucks a month to show for it.

Weak as shit ad revenue

What are my costs associated with this app?

-Annual Apple Developer Program ($120 a year)

-Power to run my server ($15 a month)

-Cost to build my server ($550)

Not including server upkeep and the initial cost of building the server, it costs me $25 a month to run this service.

I lose money every month by providing this service.

 

Do you have any other good news?

  • If this service takes off, I will be removing ads from the app completely.
  • I will more inclined to add new features if the app is making money every month.

 

 

Thanks for reading everyone ūüôā

Multiple dex files define lcom/android/vending/billing/IInAppBillingService

If you began to implement Google’s API V3 of their In App Billing Service, and switched to¬†android-inapp-billing-v3 made by¬†anjlab, you might get this error message

The reason this is happening is because you have the same library in there twice. Once from before, and again when his library adds the same files.

The solution is simple, delete the aidl folder in your <project>/app directory. Clean, then rebuild and it will work!

Android – Creating a simple hamburger menu in title bar

What we want:

A standard hamburger style menu that can be used in the active title bar of an Android Application

Android hamburger menu collapsed

Android hamburger menu collapsed

How to do it:

Create a menu layout in the menu directory of the res folder, reference it in your activity, and program functionality to each menu item.

Menu-item file:

If the folder “menu” doesn’t exist in “res”. You will need to create it. See below:

Android resource menu layout

Android resource menu layout

Contents of new file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/iconHamburger"
        android:icon="@drawable/hamburger"
        app:showAsAction="ifRoom|withText"
        android:title="Other">
        <menu>
            <item
                android:icon="@drawable/settingsicon"
                android:id="@+id/menuItemSettingsicon"
                android:onClick="launchSettings"
                android:title="Settings"></item>
            <item
                android:icon="@drawable/browser"
                android:id="@+id/menuItemWebsite"
                android:onClick="launchBrowser"
                android:title="Website / Status"></item>
            <item
                android:icon="@drawable/bug"
                android:id="@+id/menuItemBugReporting"
                android:onClick="launchEmail"
                android:title="Bug reporting"></item>
            <item
                android:icon="@drawable/beer"
                android:id="@+id/menuItemBeer"
                android:onClick="launchDonateActivity"
                android:title="Donate / Buy me a beer"></item>

        </menu>

    </item>
</menu>

You’ll need a hamburger icon, which you can obtain off google images anywhere. I also have icons on each menu item. The end result looks like this:

Android hamburger menu expanded

Android hamburger menu expanded

We’ll need to make the hamburger expand on click, so create the following method

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.mainpagemenu, menu);
        return true;
    }

 

You’ll notice that in the XML file, I have an onClick property that refers to a method we haven’t implemented in this java file. We’ll add the methods to the file now (The method will need to accept a Menu item!)

    public void launchEmail(MenuItem menuItem)
    {
        //do whatever you want in this method
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("message/rfc822");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
        try {
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hi, I found a bug with your app -");
            startActivity(emailIntent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(getApplicationContext(), "You have no email client installed! Email me at [email protected]", Toast.LENGTH_LONG).show();
        }

    }

 

That’s it! That’s how you create a very simple Hamburger menu!

Automate backing up visualsvn repositories with Windows Powershell

To backup your VisualSVN repositories, you will need the following

  1. Windows powershell installed and configured to allow scripts to run. If you’re unsure of how to enable powershell scripts to run locally, see this superuser thread
  2. A place to backup files. I have mine synced to a local folder, which is then synced to OneDrive

Step one. Create a text file and change the extension to .ps1

The file would be something like VisualSVNscript.ps1

Step two. Add the following lines to the file

#Name of project1
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project2
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project3
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
#Name of project4
Remove-Item -Recurse -Force <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>
svnadmin.exe hotcopy <PUT YOUR PROJECTS SOURCE DIRECTORY HERE> <PUT YOUR PROJECTS DESTINATION DIRECTORY HERE>

You will need to do this PER project! Hotcopy can only copy to an empty directory, so we delete the contents of the directory first then copy the newest code to the directory. Save the file and exit

Step three. Use Windows Task Scheduler to run the script automatically for you.

  1. ¬†Press Start and start typing “Task Scheduler”. Click on it.
  2. Click create basic task, name the task “VisualSVN backup” or anything you like and select desired frequency
  3. For a command enter in “powershell -file <pathtoscript>” and click Finish

That’s it! Your VisualSVN projects will now automatically be backup for you!

Xamarin.Forms – iOS/iPhone – Detecting if user said no to push/remote notifications

I assume if you’re reading this, you’re familiar with dependency injection in Xamarin Forms. What you’d create in your portable project (Your Xamarin Forms application) is the following

Xamarin.Forms custom class

public interface INotificationsInterface
{
    bool registeredForNotifications();
}

In your Xamarin.iOS project,  implement the interface with the following:

public class NotificationsInterface: INotificationsInterface
{
	public bool registeredForNotifications()
	{
		UIUserNotificationType types = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;
		if (types.HasFlag(UIUserNotificationType.Alert))
		{
			return true;
		}
		return false;
	}
}

In your main activity for your Xamarin.Forms application, perform the check as follows:

if (DependencyService.Get().registeredForNotifications())
{
	Debug.WriteLine("alerts enabled!");
} else
{
	String warningAboutAlerts ="The point of this applications is instant alerts" +
" but you choose not to receive alerts. You will need to manually check the notifications" +
	   "page or go into your iPhone's system settings to reenable alerts";
	Debug.WriteLine("No alerts allowed!");
	mainLayout.Children.Add(new Label
	{
		Text = warningAboutAlerts,
		TextColor = Color.Red,
		FontSize = 14
	});
	
}

Fairly simple stuff! For my code above, replace mainlayout with whatever you want… a dialogue box, disabling/enabling menu items… it’s entirely up to yourself!

 

 

Dotnetcore 1.1 – Entity Framework Core – Update database after making changes to the model

You may have noticed that all the blog posts make mention to commands that don’t exist. Such as update-database and other migration like commands

This is because these classes no longer exist in dotnetcore. If you want to save the changes you’ve made to a database, here are the following commands to issue in a command prompt, power shell or through VS Code

dotnet ef migrations add nameOfMigrationHere

And then run

dotnet ef database update

Check the database of your target and your changes will be there! You’ll even notice a table in your database showing the migration

Xamarin – Did not find reference matching RestoreAssemblyResources AssemblyName metadata

Did you recently remove a package, but Visual Studio insists it’s there? Or did you readd it and VS seems to disagree? People on the Xamarin Forums tend to get good luck cleaning/rebuilding, and it miraculously starts working again for them. I wasn’t so fortunate and wasted a lot of time taking their word for it.

 

My exact error message

Error Did not find reference matching RestoreAssemblyResources AssemblyName metadata 'Google.MobileAds, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' iosTests

If you’re like me, you’ve tried readding the package, modifying your packages.config file and still nothing is working

Here’s what you need to do:

  1. Locate your  .csproj file and open it in a text editor (Double clicking opens it in VS)
  2. Press CNTRL + F and search for the offending library
  3. Comment out the entry or delete it
  4. Build the project again (Since it’s Xamarin, it will take a lifetime to build) and it will hopefully work again!
  5. Success! 

I spent days trying to figure this out. When we as Xamarin developers run into issues like this, we need to share our solutions since there is little to no support from Xamarin. I hope all my fellow Xamarin developers will find this useful!

Displaying AdMob ads on iOS with Xamarin Forms!

All the tutorials on displaying ads on iOS are currently broken, as the package used to display ads has been removed.

There is a new package, however the usage example it gives is for an iOS dependent project. It will not work/compile for use in Xamarin Forms

The approach is the same however, You are rendering a View you declare in your portable project

Install the correct ad package, it should look like this in Nuget Package Manager

xamarin

Here is the view I created in my Xamarin Forms project.

namespace CanadianClassifiedsAlerter
{
    public class AdMobView : View
    {
        public AdMobView() { }
    }
}

In my iOS project, I created a ViewRenderer.

[assembly: ExportRenderer(typeof(AdMobView), typeof(AdMobRenderer))]
namespace CanadianClassifiedsAlerter.iOS
{
    public class AdMobRenderer : Xamarin.Forms.Platform.iOS.ViewRenderer
    {
        const string bannerId = "THISISWHEREMY_AD_IDGOES";

        BannerView adView;
        bool viewOnScreen = false;

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);
            // Setup your BannerView, review AdSizeCons class for more Ad sizes. 
            adView = new BannerView(size: AdSizeCons.Banner, origin: new CGPoint(-10, 0))
            {
                AdUnitID = bannerId,
                RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
            };

            // Wire AdReceived event to know when the Ad is ready to be displayed
            adView.AdReceived += (object sender, EventArgs ea) => {
               
                viewOnScreen = true;
            };

            adView.LoadRequest(Request.GetDefaultRequest());
            base.SetNativeControl(adView);
        }
    }


}

Now, after all is said and done to add it to my page, it’s this simple!

 

 mainLayout.Children.Add(new AdMobView
            {
                WidthRequest = 320,
                HeightRequest = 50
            });

Your end result should look like this

iosAdmobFinalResult

EDIT: Sample project files are here

Unused Canadian Classifieds Portable Project Files (Xamarin Forms).

I decided to use Xamarin.iOS instead for this project, so feel free to do whatever with those files.

 

EDIT: A user followed the advice from this article and got the following error…

‚ÄúFoundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[AppDelegate window]: unrecognized selector sent to instance 0x79aa9b10‚ÄĚ

He override the Window with the following code and away it worked!

public override UIWindow Window {
get
{
return UIApplication.SharedApplication.KeyWindow;
}
}

No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com

If you receive the following error message after trying to run an Xamarin application in Visual Studio

"No valid iOS code signing keys found in keychain. You need to request a codesigning certificate from https://developer.apple.com. <YourAppName>"

What this basically means is that you need to create or log into your Apple ID in XCode itself and get a certification straight from Apple.

There is a great article on the Xamarin website on how to do this, check it out here

https://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/#Using_Xcode

If you still get the error message, make sure you have the iPhone simulator selected

 

Untitled

 

Untitled2