How to send Push Notifications from an iPhone

Introduction

If you’re an iOS or Android developer, you probably have a couple of apps at their respective stores, and some of your apps maybe all of them support push notifications.

Google has a great tool for doing it: Firebase. With Firebase you can setup your app to receive push notifications, send push notifications, see the statistics of your app and so on.

But for accessing the painel you need to be on a computer, login and then send the push notification to your app. What if you could send it from your iPhone with only the server key and topic needed ?

Push Robot 

With Push Robot you can send Push Notification to all your apps,  you can also see your sent notifications, duplicate one of your last notifications and get some help at the Help Session.

In order to make it simple to send push notifications to your app through FCM, The Push Robot app requires only the server Key of your App, the topic your app is registered and an internet connection.

To get the Server Key:

  1. click the settings icon/cog wheel next to your project name at the top of the new Firebase Console
  2. Click Project settings
  3. Click on the Cloud Messaging tab
  4. The key is right under Server Key

Simulator Screen Shot - iPhone 8 Plus - 2017-10-15 at 15.58.23

After you setup everything, you can send your Push Notification and that’s all. You can ask me anything in the comments session.

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

Advertisements

Why should you use CocoaPods?

This blog post has the intention to show to beginners the tool called CocoaPods, if you’re already familiar with it you may find it boring because I’ll probably show you something you already now.

What’s CocoaPods?

“CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 37 thousand libraries and is used over 2.6 million apps. CocoaPods can help you scale your projects elegantly.”(CocoaPods)

If you’re familiar with Rails, you may remember the Gemfile system, and yes, it works just like that. In fact CocoaPods is a gem for Ruby. You can contribute for the project by sending a pull request on the official repository.

 

The advantages of using CocoaPods

You are ready to develop your first iOS project, you’re full of ideias, at first having a dependency manager seems to be pretty not necessary, but remember, you app won’t be the same after every update, in fact, if you’re planning to build the next successful app, you may need starting worrying about how to organize it, this where CocoaPods comes in.

Managing a project dependencies by hand it is not the best ideia, actually, it is a terrible idea, imagine having a project with 50 dependencies and having to update all of them ? Scary huh ? That’s the reason you need a project manager, with CocoaPods if you want to update a pod(That’s how a dependency is called in CocoaPods, like a gem in Ruby) you just need to type:

pod update the_name_of_the_pod

and it will do all the work for you, after that you just need to recompile your project on XCode, and that’s all.

Another reason to use CocoaPods is: a lot of big companies are using it, like Facebook , Google and many others.

You have a lot of support, there are thousands of apps using it, and Stackoverflow if full of questions about it.

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

Swift: How to check if your app is running on a Device or a Simulator ?

Sometimes you need to check if the app is running on a device or a simulator. Why? If you’re using GoogleMobileAds lib you may need to verify is you’re on simulator to show the testing ads provided by Google.

Bildschirmfoto 2017-09-22 um 15.48.38

Happily there’s a way to do it. I personally prefer creating a struct, since I don’t need a class for it.

So let’s get started:

struct Platform {

    static let isSimulator: Bool = {

        var isSim = false

        #if arch(i386) || arch(x86_64)

          isSim = true

        #endif

        return isSim

    }()

}

 

What does the code do ? It basically checks if the architecture is i386 or x86_64 which means a computer.(Simulator)

The arch(i386) build configuration returns true when code is compiled for the 32–bit iOS simulator.

Then you can use it on your code:

   if(Platform.isSimulator){

    //your code goes here

  }

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

iOS – How to round the corners of a button

In this post I’m going to cover how to round the corners of a button in iOS.

I’ve seen a lot of solutions for this, but I found a really simple one.

First of all, you need to select the button and then go to the Object Inspector and click on the + button, then you need to create the keypath: layer.cornerRadius type as a number, then add the value 4 or the value you want as shown below.

Captura de Tela 2016-02-03 às 12.11.12

After that you can run your app and see the result.

PS: you can only see the result when running the app

That’s all for today. See you in the nexts posts

Swift 3.0: How to call a method on main thread?

Hi guys, long time no posting on my blog, from now on I’m going to post a lot of useful stuff about Swift 3.0+.

Most of the time when we are building an app we need to make a method call on main thread even if we are not actually on main thread.

The most common case is when we are using tableview and need to refresh its content like this:

self.tableView?.reloadData();

If you run the code above it won’t work properly or it will show an error, because you need to run it in the main thread. To make this code actually work, you need to call it like this:

 

        DispatchQueue.main.async(execute: {() -> Void in

             self.tableView?.reloadData();

        })

DispatchQueue manages the execution of work items. Each work item submitted to a queue is processed on a pool of threads managed by the system.

Basically the code above is calling the class DispatchQueue with the property main, which means you want to call the method inside the main thread, this method won’t return anything.

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

How to send Push Notifications from a Mac OS X – Push Robot

Mobile Developers love to imagine the users of their apps using the app all day. Push notifications allows developers to reach their users and perform small tasks even when users aren’t actively using an app.

Google has created Firebase Cloud Messaging for helping developers sending Push Notifications to their apps. You just need to login to your Google account and after some setup, you can easily send push notifications. What if you could send notifications from your Mac ? With this in mind, I’ve decided to create a Mac OS X App called Push Robot.

Push Robot allows you to send Push Notifications to your apps using FCM, all you need is the Server Key and the Topic or Device’s Token(to send push notifications to a single app).

Screen Shot 2017-04-12 at 07.54.21

To get the Server Key:

  1. click the settings icon/cog wheel next to your project name at the top of the new Firebase Console
  2. Click Project settings
  3. Click on the Cloud Messaging tab
  4. The key is right under Server Key

Now you can send a push notification to a topic which can reach millions of users or for specific users using the device’s token.

Acknowledgment

Thanks for reading this post, it is always a pleasure writing for you guys. If you like what you just read and somehow you want to support me, you can become a Patreon . Being my Patreon makes you get my private posts about programming with iOS and Ruby.

If you’d like to know more about me or what I do, you can follow me on Instagram or Twitter .

See you next time!

Shoucast Streaming in iOS (Objective-C)

In this post I’m going to cover how to build an iOS app that streams songs from Shoutcast server.

  1.  Open your XCode and Create a new project, select Single View Application and click in Next

Captura de Tela 2015-12-01 às 22.18.42

2. Name your app for Shoutcast, and then select Objective-C, and click in Next

Captura de Tela 2015-12-01 às 22.18.58

3. Create a button and name it play. This button will start the streaming

Captura de Tela 2015-12-01 às 22.26.59

4. Go to View->Assistent Editor->Show Assitent Editor

Captura de Tela 2015-12-01 às 22.27.39

5. Create an action called playMusic like the picture below:

Captura de Tela 2015-12-01 às 22.32.23

6. Open your ViewCotroller.h to create a property called myStreaming(you should create this property as strong, if you don’t do this the streaming will stop after 2 seconds)

Captura de Tela 2015-12-01 às 22.35.41

7. Now go to your ViewController.m and inside the method playMusic you should call the property you defined in your h file.

The First thing you need to have is the streaming URL (shoucast’s urls should have the address and the port), then your need to init the streaming property, after that you should define the source type, in our case is streaming, after all you just need to set shouldAutoPlay to NO and prepare to play the streaming and finally play.

– (IBAction)playMusic:(id)sender {    

 NSURL *myUrl = [NSURL  URLWithString:@”http://colinawebradio.com.br:9986″];

 self.myStreaming = [[MPMoviePlayerController alloc] initWithContentURL:myUrl];

  self.myStreaming.movieSourceType =         MPMovieSourceTypeStreaming;

   self.myStreaming.shouldAutoplay = NO;

   [self.myStreaming prepareToPlay];

   [self.myStreaming play];

}

After all, run your app and listen to the radio 🙂

That’s all, thanks :).

If you have any questions, feel free to ask.

See you guys next time!