Showing posts with label Objective - C. Show all posts
Showing posts with label Objective - C. Show all posts

Sunday, 1 May 2016

HB Blog 109: Content Assist - The Developer's Friend.

Android Studio and similar other IDE's provide various features to developers which make a comfort environment for them. Hence, it is called as Integrated Development Environment (IDE). More technical, an integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development. One of the most helpful feature is the content assist.

Content/Code assist helps the developer to write code faster and more efficiently. This is achieved by simplifying the task of coding to allow it to focus on the business task being coded. Based on the context of the code, content assist provides the developer with a list of accessible keywords according to a programming language specification, variable, methods, data types.
Autocomplete: - Autocomplete, or word completion, is a feature in which an IDE predicts the rest of a word a user is typing.

For example, in an XML context, when the developer types an opening tag "<" he is offered a list of tags via autocomplete, contextualized following the DTD or XML schema of the document. As the developer types more letters, the offered choices are filtered to only retain the relevant completions. When the developer finally completes the tag, the editor automatically generates the closing tag.

Another example, a developer can just type in the first letter if lowercase and the uppercase letters from a type/variable name then press Ctrl+space to be offered all the choices that match the entered letters that are valid for the current context (class name, interface name, variable or field names).

Code snippet/templates: - Code snippets allow the developer to add a complex coding structure by typing a minimal amount of text. Code snippets can only be used in a valid context (statements snippets are only offered when you can insert statements).

Specifically, in Android Studio ctrl+space (content assist) does 50% work of the developer's work.
Android studio has few more interesting features as well which makes development pretty simple.

Refer below link to meet Android studio,
https://developer.android.com/studio/intro/index.html

Sunday, 13 September 2015

HB Blog 94: MoPub - Mobile Ad Server Integration In Android And iOS.

MoPub is a hosted ad serving solution built specifically for mobile publishers. It helps to grow your mobile advertising business with powerful ad management. etc.
In this post, I will show how to integrate MoPub ads in Android as well as iOS.
For Android,
Here are the basic integration steps: -
  1.     Check out the files from our repository.
  2.     Add our SDK (and dependencies) to your project.
  3.     Create ad units in your app.
Download the MoPub Android SDK: -
The MoPub SDK is distributed as source code that you must include in your application.
MoPub Android Full SDK.zip
Includes everything you need to serve HTML and MRAID MoPub advertisements and built-in support for the Millennial Media ad network - including the required third party binaries.

Using Gradle: -
Open your project's settings.gradle file and make sure the MoPub SDK is included as a module:
include ':app', ':mopub-sdk'
Open your project's build.gradle file and add jcenter as a repository and the MoPub SDK as a dependency:
repositories {
    jcenter()
}
...
dependencies {
    compile project(':mopub-sdk')
...
}

This is required in order to resolve the MoPub SDK's compile time dependency on com.mopub.volley:mopub-volley:1.1.0.
Follow the instructions on the Android Developer Site for setting up Google Play Services. It is always recommend to use the latest version of Google Play Services. 

Load banner ads in your app: -
1. Check your AndroidManifest.xml file.
Add following permissions,
1
2
3
4
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
You’ll also need to include the following custom Activities (even though you won’t instantiate them directly):
1
2
3
4
<activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
2. Define a slot for your banner ad in your layout XML.
The MoPub SDK provides a custom View subclass, MoPubView, that handles requesting and loading ads.
Include this XML block to your Activity’s or Fragment’s layout.
1
2
3
4
<com.mopub.mobileads.MoPubView
    android:id="@+id/adview"
    android:layout_width="fill_parent"
    android:layout_height="50dp"/>
3. Load an ad into the banner slot.
In your Activity or Fragment code, declare an instance variable for your MoPubView:
private MoPubView moPubView;
You should already have created an ad unit on MoPub’s site and received an Ad Unit ID. You’ll use it now to identify that ad unit in your app and request ads from MoPub that are relevant for your users.
In your Activity’s onCreate() or your Fragment’s onCreateView() method, set your MoPubView’s Ad Unit ID, then simply call loadAd() to fetch and display the ad:
1
2
3
4
5
...
moPubView = (MoPubView) findViewById(R.id.adview);
moPubView.setAdUnitId("xxxxxxxxxxx"); // Enter your Ad Unit ID from www.mopub.com
moPubView.loadAd();
...
When the hosting Activity or Fragment is destroyed, be sure to also destroy the MoPubView by calling:
1
moPubView.destroy();

Additional Listener Interface: - MoPubView provides a listener interface, BannerAdListener, which you can use to stay informed about ad lifecycle events. 
BannerAdListener includes the following methods:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
// Sent when the banner has successfully retrieved an ad.
public void onBannerLoaded(MoPubView banner);
// Sent when the banner has failed to retrieve an ad. You can use the MoPubErrorCode value to diagnose the cause of failure.
public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode);
// Sent when the user has tapped on the banner.
public void onBannerClicked(MoPubView banner);
// Sent when the banner has just taken over the screen.
public void onBannerExpanded(MoPubView banner);
// Sent when an expanded banner has collapsed back to its original size.
public void onBannerCollapsed(MoPubView banner);

For iOS,
Here are the basic integration steps: -
  1.     Download the MoPub SDK
  2.     Add the SDK to your Xcode project.
  3.     Create and use a Banner or Interstitial ad.
Download the MoPub iOS SDK: -
The MoPub SDK is distributed as source code that you must include in your application.
MoPub Full SDK.zip
Includes everything you need to serve HTML and MRAID MoPub advertisiments and built-in support for three major third party ad networks - iAd, Google AdMob, and Millennial Media - including the required third party binaries.

Using CocoaPods: -
The MoPub SDK is available through Cocoapods, a popular dependency management system for Objective-C projects.
To download and incorporate the MoPub SDK into your project using Cocoapods, add the following line to your project's podfile:
pod 'mopub-ios-sdk'
After running pod install (if you’re setting up Cocoapods for the first time) or pod update (if you’re adding MoPub to an existing Cocoapods project), your project will be ready to use the base MoPub SDK.

Load banner ads in your app: -
You can create an ad unit (a space for ads) on the MoPub online dashboard. Upon your first visit, you'll be prompted to register your application and set up an ad unit. Afterwards, you can retrieve your ad unit ID by clicking "Get code snippet" in the top right corner of the ad unit page.
Adding a banner to your application takes only a few, easy steps:
  1.     In your view controller's header file: Import the MPAdView.h header file and declare an MPAdView *adView property. Declare that your view controller implements the MPAdViewDelegate protocol.
  2.     In your view controller's implementation file, instantiate an MPAdView, passing in your ad unit ID. This is typically done in -viewDidLoad.
  3.     Register your view controller as the adView's delegate.
  4.     Set the adView's frame and add the adView to your controller's view hierarchy.
  5.     Center the adViewon screen to account for iPhone 6 and iPhone 6 plus
  6.     Implement the -viewControllerForPresentingModalView MPAdViewDelegate method. The adView will use the view controller returned by this method to present modals when tapped. Typically your controller can simply return self.
  7.     Finally, load an ad by sending adView the -loadAd message.
// MyViewController.h
1
2
3
4
5
#import "MPAdView.h"

@interface MyViewController : UIViewController <MPAdViewDelegate>
@property (nonatomic) MPAdView *adView;
@end

// MyViewController.m
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#import "MyViewController.h"

@implementation MyViewController

- (void)viewDidLoad {
    // ... your other -viewDidLoad code ...

    self.adView = [[MPAdView alloc] initWithAdUnitId:@"<YOUR_ADUNIT_ID_HERE>"
                                                 size:MOPUB_BANNER_SIZE];
    self.adView.delegate = self;
    self.adView.frame = CGRectMake((self.view.bounds.size.width - MOPUB_BANNER_SIZE.width) / 2, 
                                  self.view.bounds.size.height - MOPUB_BANNER_SIZE.height,
                                  MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height);
    [self.view addSubview:self.adView];
    [self.adView loadAd];
    [super viewDidLoad];
}

#pragma mark - <MPAdViewDelegate>
- (UIViewController *)viewControllerForPresentingModalView {
    return self;
}

...
@end

Additional Delegate Callbacks: -
MPAdViewDelegate includes a variety of optional callbacks you can use to be notified of events, e.g. when an ad has successfully loaded, or when the ad is about to present or dismiss a modal view. Check out the MPAdViewDelegate protocol in MPAdview.h for a list of these methods.
1
2
 // Called when the banner has successfully retrieved an ad.
-adViewDidLoadAd:

Monday, 23 March 2015

HB Blog 64: REPL (Read-Eval-Print-Loop) Environment In iOS Playground File.

A read–eval–print loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise.
In a REPL, the user enters one or more expressions (rather than an entire compilation unit) and the REPL evaluates them and display the results.
    The read function accepts an expression from the user, and parses it into a data structure in memory. For instance, the user may enter the s-expression (+ 1 2 3), which is parsed into a linked list containing four data elements.
    The eval function takes this internal data structure and evaluates it. In Lisp, evaluating an s-expression beginning with the name of a function means calling that function on the arguments that make up the rest of the expression. So the function + is called on the arguments 1 2 3, yielding the result 6.
    The print function takes the result yielded by eval, and prints it out to the user. If it is a complex expression, it may be pretty-printed to make it easier to understand. In this example, though, the number 6 does not need much formatting to print.

Most recent example is Playground file. Without requiring you to compile and run a complete project, a playground provides quick feedback for the results of your coding experiments. You just need to select a .playground file in the project navigator in xcode, or create a .playground file by choosing File > New > File and selecting the Playground source template for your ios platform. Enter the code into the .playground file, and examine the results in the sidebar. The quick look option opens assistant editor which will open with a timeline view, containing a graph of these values over time.

Below  is the exapmle for fibonacci series in playground in swift language on iOS platform.

Saturday, 24 January 2015

HB Blog 54: Objective-C And(not VS) Swift.

I have been thinking a lot about the right tile for this post. Objective-C And(not VS) Swift sounds more
informative rather than comparison and differences. Afterall, we don't prefer to discriminate on basic of
languages.

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It is the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs), Cocoa and Cocoa Touch.

Swift is a multi-paradigm, compiled programming language created by Apple for iOS and OS X development. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products.

There many similarity between both of them as follows:-
1)Both are used by Apple.(I need not brief on that context.)
2)Both have same basic numeric types (Int, UInt, Float, Double).
3)Both use curly braces to group statements.
4)In both, variables are assigned using an equals sign, but compared using two consecutive equals signs.
5)In both, control statements, for, while, if, switch are similar.
6)In both, class methods are inherited, just like instance methods, self in class methods is the class the method was called on.

But,they both have few differences too,
1)In Swift, statements do not need to end with a semicolon (;), though they must be used to allow more than one statement on a line
2)In Swift, header files are not required
3)In Swift, functions are first-class objects.
4)In Swift, enumeration cases can have associated data (algebraic data types).
5)In Swift, operators can be redefined for classes (operator overloading), and new operators can be created.
6)In Swift, strings fully support Unicode. Most Unicode characters can be used in either identifiers or operators.
7)In Swift, no exception handling (though it can be emulated through use of closures).
This is not seen in Objective-C.