‘global_asax’ is ambiguos in the namespace ‘ASP’

Hello All!

Today, I’ll talk about an error message, that I had encountered while compiling my ASP.Net Web Application, which nearly, compelled me to create a new Project Solution and transfer my project files into that Solution – Old School way of getting things to work¬†ūüôā

The Global.asax, Project Classes and Web Service references were all showing the error for ambiguity.

Error.png

After struggling for 3-4 days to get my Project Solution working, I arrived at a solution.

You’ll have to delete these files from the Bin folder and then build¬†the solution again.

files.png

I hope it works for you’ll too!

Cheers!

Rohant K3

Advertisements

Reducing the Database Log File Size

Hello All,

Today i’ll talk about how to reduce the file size of the Log file of your SQL Server Database.

Log Files tend to grow to an extent that it might eat up a lot of space on your drive and for me it went to an extent that my database was down due to lack of space on the drive.

So, no apps were able to dump any record into the database at all.

Well, we’ll have to live with it though as it seems.

Log Files can be cleared using a SQL Script

ALTER DATABASE  DATABASENAME
SET RECOVERY SIMPLE;
GO
— Shrink the truncated log file to 1 GB (You can shrink upto 1 MB).
DBCC SHRINKFILE (DATABASE_log, 1000); –LOG FILE NAME
GO
— Reset the database recovery model.
ALTER DATABASE DATABASENAME
SET RECOVERY FULL;
GO

Hope this works for you too!

Cheers!

Rohant K.

Using HighCharts with ASP.Net

Hello There!

Today, we will talk about using HighCharts with ASP.Net Web Site.

I am big fan of responsiveness in a Web Site whenever it comes to a single platform for information sharing. I use HighCharts for responsive dashboards.

Since HighCharts is purely a JavaScript front-end / client side API for showing charts, we will be using DotNet.HighCharts for building up the Chart from the code-behind rather than using Client-side JavaScript.

So, first create an Asp.Net web site and run the Nuget Package Manager Console as shown below and execute the following command for Nuget to download and reference DotNet.HighCharts

Install-Package DotNet.Highcharts

PackageManager.png

After Nuget has downloaded and referenced the DotNet.HighCharts, its DLL will be automatically referenced by the Project. Please cross-check if your project references DotNet.HighCharts.dll in the references window.

TIP: If you are facing difficulties in downloading the package, then there is a download link for the DotNet.Highcharts.dll at the end of this tutorial.

References.png

In your code-behind file, add the below imports statements:

Imports DotNet.Highcharts.Enums
Imports DotNet.Highcharts.Helpers
Imports DotNet.Highcharts.Options
Imports Point = DotNet.Highcharts.Options.Point
Imports DotNet.Highcharts
Imports System.Drawing
Imports System.Net
Imports System.Runtime.Serialization.Json
Imports System.IO
Imports Newtonsoft.Json
Imports System.Data ‘ To use incase your charts is connected to the DataSet to fetch the data from database

I will be showing two examples:

  1. Column Chart (using 1 Dimensional Array)
  2. Pie Chart (using 2 Dimensional Array)

In the .aspx add the below call to the Highcharts javacript reference. Without this call, your chart will not render on the web page.

http://code.highcharts.com/highcharts.js

<%–without the call to the exporting.js, your chart will not be able to export itself to any format.–%>
http://code.highcharts.com/modules/exporting.js

Add the ASP.Net Literal Controls in the Markup as shown below:

<asp:Literal ID=”Literal_Column” runat=”server”></asp:Literal>

<asp:Literal ID=”Literal_Pie” runat=”server”></asp:Literal>

Now lets open the Code behind vb file.

Column Chart:

I am adding the below code to a event handler to launch and populate the chart with the data.

In order to show the information in Column Chart, you need information for the X Axis and the Y Axis. So, for this purpose you must have two single dimensional arrays filled up. One for the X Axis and the other for the Y Axis.

‘ COLUMN CHART WORK AREA

Dim oListXAxis As New List(Of String)()
Dim oListYAxis As New List(Of Object)() ‘ You must have the Y Axis data in the Array of type Object only. It will not be able to read through the other data types.

‘ Below, I am filling the information from the DataSet oDataSet into the Array. One for the XAxis and the other for the YAxis

Dim oArrXAxis As New ArrayList

oArrXAxis.Add(“Jan”)
oArrXAxis.Add(“Feb”)
oArrXAxis.Add(“Mar”)

Dim oArrYAxis As New ArrayList

oArrYAxis.Add(“123”)
oArrYAxis.Add(“456”)
oArrYAxis.Add(“789”)

For iCountXAxis As Int32 = 0 To oArrXAxis.Count – 1
oListXAxis.Add(oArrXAxis(iCountXAxis))
Next

For iCountYAxis As Int32 = 0 To oArrYAxis.Count – 1
oListYAxis.Add(oArrYAxis(iCountYAxis))
Next

Next, We will move to create a Chart object.

Dim chartColumn As Highcharts ‘ HighCharts Object.

chartColumn = New Highcharts(“ColumnChart”).InitChart(New Chart() With { _
.DefaultSeriesType = ChartTypes.Column, _
.Animation = New DotNet.Highcharts.Helpers.Animation(True), _
.MarginRight = 130, _
.MarginBottom = 25, _
.ClassName = “chart”}) _
.SetCredits(New DotNet.Highcharts.Options.Credits() With { _
.Enabled = False}) _
.SetTitle(New Title() With { _
.Text = “Column Charts”, _
.X = -20 _
}) _
.SetSubtitle(New Subtitle() With { _
.Text = “Source: Rohant Kunnat @ WordPress”, _
.X = -20 _
}) _
.SetXAxis(New XAxis() With { _
.Categories = oListXAxis.ToArray() _
}) _
.SetYAxis(New YAxis() With { _
.Title = New YAxisTitle() With { _
.Text = “Connections” _
}, _
.PlotLines = {New YAxisPlotLines() With { _
.Value = 0, _
.Width = 1, _
.Color = ColorTranslator.FromHtml(“#808080”) _
}} _
}) _
.SetTooltip(New Tooltip() With { _
.Formatter = “function() {” & vbCr & vbLf & “return ‘<b>’+ this.series.name +'</b><br/>’+” & vbCr & vbLf & ” this.x +’: ‘+ this.y +”;” & vbCr & vbLf & ” }” _
}) _
.SetLegend(New Legend() With { _
.Layout = Layouts.Vertical, _
.Align = HorizontalAligns.Right, _
.VerticalAlign = VerticalAligns.Top, _
.X = -10, _
.Y = 100, _
.BorderWidth = 0 _
}) _
.SetSeries({New Series() With { _
.Name = “Count of Q1”, _
.Data = New Data(oListYAxis.ToArray)}})

Literal_Column.Text = chartColumn .ToHtmlString() ‘ Sets the Chart to the ASP.Net Literal control.

Pie Chart:

I am adding the below code to a event handler to launch and populate the chart with the data.

‘ PIE CHART WORK AREA

‘ Q1 REPORT.
Dim oDTQ1Report As New DataTable
Dim oDCQ1ReportMonth As New DataColumn(“MONTH”)
Dim oDCQ1ReportCount As New DataColumn(“COUNT”)

Dim oDRQ1Report As DataRow

oDTQ1Report.Columns.Add(oDCQ1ReportMonth)
oDTQ1Report.Columns.Add(oDCQ1ReportCount)
oDTQ1Report.AcceptChanges()

oDRQ1Report = oDTQ1Report.NewRow()
oDRQ1Report.Item(0) = “Jan”
oDRQ1Report.Item(1) = “123”
oDTQ1Report.Rows.Add(oDRQ1Report)

oDRQ1Report = oDTQ1Report.NewRow()
oDRQ1Report.Item(0) = “Feb”
oDRQ1Report.Item(1) = “456”
oDTQ1Report.Rows.Add(oDRQ1Report)

oDRQ1Report = oDTQ1Report.NewRow()
oDRQ1Report.Item(0) = “Mar”
oDRQ1Report.Item(1) = “789”
oDTQ1Report.Rows.Add(oDRQ1Report)

oDTQ1Report.AcceptChanges()

‘ We’ll have to convert the DataTable into a two dimensional array for the Pie Chart to understand. So lets declare a two dimensional array as show below:

Dim o2DArrQ1Report(oDTQ1Report.Rows.Count – 1, 1) As Object

For iCount As Int32 = 0 To oDTQ1Report.Rows.Count – 1

For iCount2d As Int32 = 0 To 1

o2DArrQ1Report(iCount, iCount2d) = oDTQ1Report(iCount)(iCount2d)

Next

Next

 

Next, We will move to create a Chart object.

‘ PIE CHART

Dim chartPie ¬†As Highcharts ‘ HighCharts Object.
chartPie = New Highcharts(“chartPie”).InitChart(New Chart() With { _
.Type = ChartTypes.Pie, _
.MarginTop = 80, _
.MarginRight = 40, _
.Animation = New DotNet.Highcharts.Helpers.Animation(True), _
.Options3d = New ChartOptions3d() With { _
.Enabled = True, _
.Alpha = 45, _
.Beta = 0 _
} _
}).SetCredits(New DotNet.Highcharts.Options.Credits() With { _
.Enabled = False}) _
.SetTitle(New Title() With { _
.Text = “Pie Chart” _
}).SetTooltip(New Tooltip() With { _
.PointFormat = “{series.name}: <b>{point.value}</b>” _
}).SetPlotOptions(New PlotOptions() With { _
.Pie = New PlotOptionsPie() With { _
.AllowPointSelect = True, _
.Cursor = Cursors.Pointer, _
.Depth = 35, _
.DataLabels = New PlotOptionsPieDataLabels() With { _
.Enabled = True, _
.Color = ColorTranslator.FromHtml(“#000000”), _
.Formatter = “function() { return ‘<b>’+ this.point.name +'</b>: ‘+ this.y; }”
} _
} _
}).SetSeries(New Series() With { _
.Type = ChartTypes.Pie, _
.Name = “Q1 Report”, _
.Data = New Data(o2DArrQ1Report) _
})

Literal_Pie.Text = chartPie .ToHtmlString() ‘ Sets the Chart to the ASP.Net Literal control.

EXPORTING THE CHARTS

In a way, it is a great practice, if the user is able to export the charts as an image or a PDF document. So, in order to enable the export of the Charts, please include the following call to the Java Script in your Default.aspx

http://code.highcharts.com/modules/exporting.js

After adding this script call, the Export button will appear on the top right corner of the Chart.

ContextMenu.png

The option lets you to export the Chart to various file types.

And that is it!, you should be getting your Charts on the Web Page.

It is quite difficult for me to show a complete example of all the chart types available with Highcharts in this blog. Nevertheless, I would definitely come up with a solution in case you have any problems for implementing any other chart type available with HighCharts.

If you have any trouble getting around this tutorial, please don’t hesitate to leave a comment on my blog.

With a big public demand in form of comments and eMails to me for the Download link of the above tutorial, Good News!!, I have a download link for it now. Please click the below link for the above tutorial.

Download Link for the above blog

TIP: The entire code resides in the Default.aspx file and Default.aspx.vb file. If the project for reason or dependency does not run, then just copy the Default.aspx and Default.aspx.vb file into another project of yours. In this case, you will have to download the DotNet.Highcharts.dll to your project as well. You can download from the below link.

Download Link for DotNet.HighCharts.dll

Cheers!

Rohant K

 

Apple Push Notification Production certificate not recognized by PushSharp

Hello There,

Today, i’ll talk about the problem, where your Production Apple Push Notification Service Certificate is not recognized by Push Sharp.

I use Push Sharp [Github] to send push notifications to the iOS devices.

Somehow things were Ok, until I was using my development / sandbox certificate. But then when the Production APNS certificates were being used to send Push Notifications, I received an exception in PushSharp which read:

You have selected the Production server, yet your Certificate does not appear to be the Production certificate! Please check to ensure you have the correct certificate!

After thoroughly revisiting other tech blogs, I found that Apple has changed the name in the Production Service from : “Apple Production IOS Push Services” to “Apple Push Services”

So, to fix this:

  1. Go to ApplePushChannelSettings.cs file
  2. Go to CheckProductionCertificateMatching(bool production) method
  3. Change the If condition from
    1. if (production && !subjectName.Contains(“Apple Production IOS Push Services”)) to¬†if (production && !subjectName.Contains(“Apple Push Services”))
  4. Secondly, in the¬†bool DetectProduction(X509Certificate2 certificate) function change the If Condition from¬†if (subjectName.Contains(“Apple Production IOS Push Services”)) to¬†if (subjectName.Contains(“Apple Push Services”))

That is it! Build your project and your distribution / production push notification service is ready to use!

-Cheers!

Rohant K.

 

MapBox GL JS: Resize maps on hidden divs or Modal Dialog boxes in Bootstrap. Server Side event.

Hello There,

Today, we i’ll show you how to resize a map on a Bootstrap Modal Dialog box which is hidden.

You may sometimes find it easy to show up a map window in Bootstrap Modal Dialog Box than occupying a large real estate on your web page.

I am using MapBox since it has got the most intuitive, extended open-source Map JS. Moreover it is much faster to render on a Web Page than Google Maps. So if you have a not-so-complicated requirement to show up on a Map, I would recommend MapBox.

So, lets get started..

If you dont have a MapBox Account, it is required that you create an account first. You can visit https://www.mapbox.com/studio/signup/ . After signing up, you will receive a API Key for your account, which you can use for your projects.

STEP 1:

Create ASP.Net Web Page Project.

STEP 2:

Go to Default.aspx (or any other aspx file, you want the map to be drawn..) and add the following lines of code below the <asp:Content /> declaration.

<meta name=’viewport’ content=’initial-scale=1,maximum-scale=1,user-scalable=no’ />
https://api.tiles.mapbox.com/mapbox-gl-js/v0.15.0/mapbox-gl.js
<link href=’https://api.tiles.mapbox.com/mapbox-gl-js/v0.15.0/mapbox-gl.css&#8217; rel=’stylesheet’ />

STEP 3:

Add the Style tag. This style tag defines the style for the map. Below the map is saved in a map variable, so the style is defined for the #map variable.

<style>
body {
margin: 0;
padding: 0;
}

#map {
position: absolute;
top: 0;
bottom: 0;
width:100%
}
</style>

STEP 4:

Add a Bootstrap Modal to show the map.

ModalMap.png
Some how WordPress did not allow me to add this markup as a plain text. So adding it as a screenshot. Bear with me. ūüôā

STEP 5:

Add the java script to handle the bootstrap modal dialog box and also set the Map attributes.

mapboxgl.accessToken = ”; // Enter you MapBox Access Token here.

var map = new mapboxgl.Map({
container: ‘map’, // container id
style: ‘mapbox://styles/mapbox/streets-v8’, //stylesheet location
center: [, ], // starting position. I have two variables sLatitude and sLongitude here to pass the Latitude and Longitude from the Server Side.
zoom: 9 // starting zoom
});

function MapModal() {
$(‘#Map_Modal’).modal();
}

function MapResize() {
map.resize(); // We will use the map.resize() function, to resize the MapBox map  once the modal has finished loading.
}

// Given that your modal has the id #modal
// and your map is under the variable map. The ‘shown.bs.modal’ event handler is an in-built event handler for Bootstrap Modals.
$(‘#Map_Modal’).on(‘shown.bs.modal’, function () {
map.resize();
});

STEP 6:

On the server side we must now pass the values of Latitude and Longitude to the two variables sLatitude and sLongitude. Below is the full code from the Server Side.

Partial Class _Default
Inherits Page

Protected sLatitude As String
Protected sLongitude As String

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

sLatitude = “58.548025”
sLongitude = “23.6063006”

End Sub

Protected Sub Button_Click_Click(sender As Object, e As EventArgs)

‘ First to execute the script to show the modal dialog box.
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), “LaunchServerSide”, “$(function() { MapModal(); });”, True)

‘ Second, to execute the resize function of the MapBox.
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), “LaunchServerSide”, “$(function() { MapResize(); });”, True)

End Sub
End Class

And that is it!

You should be having the map drawn properly on a Bootstrap Modal Dialog Box.

-Cheers!

Rohant K.

 

How to get the Windows User Name of the logged in user in ASP.Net, IIS

Hello There!

So, today i’ll speak ¬†about how you can get the User ID of the current user who has logged into the Web Application.

Lets consider the Web Application is hosted in IIS.

Here, I am avoiding all the boiler plate code to create and set up your project and host into the IIS.

There are three ways to get the logged in User ID in ASP.Net.

FIRST WAY

<authentication mode=”Windows”/>

You can add the authentication tag into the <system.web> tag in the Web.config file of your project.

Enable the Anonymous access in IIS. You will find this setting in your Application under the Authentication Option.

Authentication.png EnableAnonymousAuthentication.png

Write the below lines of code in your application CS or VB file.

  1. System.Environment.UserName .. Will give you the Computer Name
  2. Page.User.Identity.Name .. Will give you Blank
  3. System.Security.Principal.WindowsIdentity.GetCurrent().Name .. Will give you the Computer Name

SECOND WAY

<authentication mode=”Windows”/>

You can add the authentication tag into the <system.web> tag in the Web.config file of your project.

Disable the Anonymous access & Enable Windows Authentication in IIS. You will find this setting in your Application under the Authentication Option.

Authentication.pngEnableWindowsAuthentication.png

After setting the Application to enable Windows Authentication, you will have to migrate your application to a Classic .NET AppPool and enable the  Integrated Pipeline for the Classic .Net AppPool inside the IIS.

AppPool.png

Write the below lines of code in your application CS or VB file.

  1. System.Environment.UserName .. Will give you ASPNET. i.e the account that is used to run the Asp.Net service.
  2. Page.User.Identity.Name .. Will give you Domain\Windows Account Name
  3. System.Security.Principal.WindowsIdentity.GetCurrent().Name .. Will give you Computer Name\ASPNET

 

THIRD WAY

<authentication mode=”Windows”/>¬†<identity impersonate =”true”/>

You can add the above tags into the <system.web> tag in the Web.config file of your project.

Disable the Anonymous access & Enable Windows Authentication in IIS

Authentication.pngEnableWindowsAuthentication.png

After setting the Application to enable Windows Authentication, you will have to migrate your application to a Classic .NET AppPool and enable the  Integrated Pipeline for the Classic .Net AppPool inside the IIS.

AppPool.png

Write the below lines of code in your application CS or VB file.

  1. System.Environment.UserName .. Will give you Windows Account Name
  2. Page.User.Identity.Name .. Will give you Domain\Windows Account Name
  3. System.Security.Principal.WindowsIdentity.GetCurrent().Name .. Will give you Domain\Windows Account Name

* Browser will ask you for the user name and password if the Windows Authentication is enabled.

That’s all you have to do to fetch the Windows User ID in ASP .Net IIS environment.

Cheers!

Rohant K.

 

Using Microsoft Exchange Web Service – EWS

Hello There,

We do have requirements to integrate your application with the eMail, either by sending them or by reading them (Yes! Рit is possible), for this purpose, Microsoft has a cool new protocol called as the Exchange Web Services.

If you have an eMail Exchange Server 2007 and above already set up, then it is a cake walk to integrate your application with the Exchange Server eMail using EWS.

NOTE: At the time of writing this article EWS API 2.2 was the latest version.

NOTE: I am using VB .Net for this example

So lets get started!

Firstly, you’ll need to download the EWS API from the Microsoft MSDN website, using the below URL and follow the installation procedure mentioned there:

https://www.microsoft.com/en-us/download/details.aspx?id=42951

After installing the EWS API 2.2, you must now turn on your Visual Studio environment and create a new Project:

VS1.pngnewProject.png

Click ‘Ok’ to create a new project.

Now lets turn our focus on the steps to reference the newly installed Exchange Web Service. We will have to manually reference them into our project. To do this:

Click the add reference menu item by right clicking the project > Add > Reference

reference

A Reference Manager window opens upReferenceManager.png

Click Browse on the left pane and then click Browse button again from the Footer

It will open up the Windows Explorer. Navigate to the below path, which ideally the default path where the Exchange Web Services are installed.

 

C:\Program Files\Microsoft\Exchange\Web Services\2.2

reference2.png

There are two dlls that you will have to import into your project. Click Add after you select them both.

reference3.png

You need to keep these information handy before you follow the code below:

  1. Your Microsoft Exchange Server version (For example Exchange Server 2007 or Exchange Server 2010 etc.)
  2. eMail ID, Password and the Domain Name that you will be using to send the eMail from
  3. URL of your exchange web service. Ideally, it is the exchange server name. You can find your exchange server name, by going into the Account Settings. The highlighted area in the image below is the server name. So the URL of the exchange web service would be https://<Server Name>/EWS/Exchange.asmx . Clicking on the link the web service page of the Exchange should open up. It will ask you for your user name and password.
  4. AccountInfo1.png
  5. An HTML File, for you to send an eMail (You can even send a plan text eMail.)

Now lets send an eMail using EWS!

Follow the code block below:


' We create an object of the Exchange Server. 
' In the argument, I specify the Exchange Server Version. Mine is 2010.
Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP2)
service.Credentials = New WebCredentials(<eMail ID of the Sender>, <Password of the sender>, <Domain Name under which your Exchange Server resides>)

' This is your Exchange Web Service URL
service.Url = New Uri("https://<Server Name>/EWS/Exchange.asmx")

' Set up the recepients eMail IDs
Dim oEmail As New EmailMessage(service)
oEmail.ToRecipients.Add(<Recipient EMail ID>)

' Read the HTML File and store it in a String.
 Dim sHtml As String = System.IO.File.ReadAllText("C:\index.html")

' EMail Subject, Body Block

 oEmail.Subject = "SUBJECT"
 oEmail.Body = New MessageBody(sHtml)
 oEmail.Body.BodyType = BodyType.HTML
 oEmail.Send()

' To trace the request and responses while using EWS. It helps to find out where your service is wrong.
 service.TraceEnabled = True
 service.TraceFlags = TraceFlags.All

and thats it!, this is how you can send an eMail using Microsoft Exchange Service API 2.2 web service.

You can extend the capability further, by reading the eMail messages from the inbox using the Exchange Web Service.

Let me know your comments!

-Cheers!

Rohant K.

 

Implementing 3D Touch Quick Launch with Objective C

Hello There!

Today, we will talk about implementing the 3D Touch for iOS Devices using ¬†“OBJECTIVE C“.

I will take couple of minutes (please bear :)) to vent out my frustration at Apple KB for giving Objective C a step-motherly treatment for promoting their retarded Swift language for documenting new features.

The reason I have emphasized Objective C above is because of a reason; there isn’t any proper documentation available written in¬†Objective C for using / implementing 3D Touch. I did spend time to understand and implement 3D Touch in Objective C and I don’t want others to through the same process. OK – So Let’s Get Started !!

This blog assumes the reader has a knowledge of Objective C, XCode IDE and Apple’s newest feature – 3D Touch!

There are 5 Steps to implement this!

Step 1:

Open Xcode and¬†create a Single View Application, with the name “test3D”

Screen Shot 2015-12-19 at 1.52.42 PM.pngScreen Shot 2015-12-19 at 1.53.55 PM.png

Step 2:

You need to remember, that the Quick Launch feature of 3D Touch, is actually executed from your Home Screen. So, you need to keep the following attributes ready:

  1. Image for the Quick Launch
  2. Quick Launch Shortcut Title
  3. Quick Launch Sub-Title

Step 3: In your XCode Project, open the Assets.xcassets image catalog file, and right click on vacant area, you will be shown a context menu option. Click the “New Image Set” menu.

Screen Shot 2015-12-19 at 2.07.39 PM.png

After clicking the New Image Set menu, you will be shown an area, where-in you can drag and drop your image on the three image image placeholders, as shown below:

Screen Shot 2015-12-19 at 2.13.21 PM.png

You are required to drop three images, one onto each placeholder.

I dropped in an image for 1x at 35px X 35px and for 2x – 70px X 70px and for 3x – 105px X 105px

Remember: For each menu option, there would be a new Image Catalogue that needs to be created.

For now lets use only a single menu for our 3D Touch Quick Launch example. An appropriate / meaningful name must be given to each of the image set catalogue.

Step 3:

Now lets shift our focus on the Info.plist file we have in our project.

Here you need to create an Array of Dictionary type for each of the Quick Launch menu option.

In the Info.plist file, right click the row and click “Add Row”

Screen Shot 2015-12-19 at 3.07.37 PM.png

And then add the UIApplicationShortcutItems Key with the Type Array.

Screen Shot 2015-12-19 at 3.08.18 PM.png

Now add a new Dictionary within the newly created UIApplicationShortcutItems array. Right click on the UIApplicationShortcutItems array and click Add Row as shown below:

Screen Shot 2015-12-19 at 3.12.45 PM.png

Now add Item 0 with type Dictionary

Screen Shot 2015-12-19 at 3.13.00 PM.png

You need to add 4 attributes into this Dictionary:

  1. UIApplicationShortcutItemTitle
  2. UIApplicationShortcutItemSubtitle
  3. UIApplicationShortcutItemType
  4. UIApplicationShortcutItemIconFile

UIApplicationShortcutItemTitle: Here is where you add give title to your Quick Launch menu item

UIApplicationShortcutItemSubtitle: Here is where you add a “meaningful” subtitle to your Quick Launch Shortcut Item

UIApplicationShortcutItemType: You must give a name to your ShortCut item. This name will be identified in this application, when the QuickLaunch Item will be pressed. So again, please give a meaningful name to it

UIApplicationShortcutItemIconFile:¬†It is here that you refer the name of your Icon Catalogue in Step 2. In our example it was just by the name “Image”.

As shown below, we add the four Quick Launch attributes to the Dictionary item:

Screen Shot 2015-12-19 at 4.19.29 PM.png

Step 4:

Now we will shift our focus to the AppDelete file in our project. Click open the AppDelegate.m file and add the completionHandler for the ShortcutItem

AppDelegate.h

Screen Shot 2015-12-19 at 4.56.37 PM.png

*NOTE: I have declared a global variable by the name

AppDelegate.m

Firstly, Add the Below code into application:didFinishLaunchingWithOptions function

Screen Shot 2017-01-11 at 10.24.52 PM.png

* I have removed few boiler plate code here from the AppDelegate.m

Add Global Variable with the name asShortCutType

Screen Shot 2015-12-19 at 4.58.37 PM.png

Screen Shot 2015-12-19 at 4.58.47 PM.png

Please note that in the shortcutItem.type check, we are specifying the name that we had added into the UIApplicationShortcutItemType attribute –¬†<Product Bundle Identifier>.Square

By now, your application should be having a Quick Launch short cut item popping out, when you press on the application icon in the Home Screen

IMG_4341.PNG

Now when you press the Square Quick Launch menu item, the completion handler in the AppDelete.m gets fired. It is here that, if you have multiple menu item, then you can identify it by using Global Variable declared in the AppDelegate file.

In our example, the global variable is by name asShortCutType

ViewController.m

Add the reference to AppDelegate.h file. And add the code in the viewDidLoad event of the ViewController. It is here that the value of the variable in the AppDelete.h file gets passed to the ViewController, and the ViewController gets notified, which menu option was clicked.

Screen Shot 2015-12-19 at 5.11.35 PM.png

Step 5: (Last but very important!)

Now that you are enjoying that the Quick Launch is getting fired, there is one more thing to apply the 3D Touch Quick Launch completely.

There is a stage in the application, where in the application is in the background state, when you press the home button.

In that case, the viewDidLoad event will not fire at all and your ViewController will not get to know, which menu option got clicked.

There is a workaround for this too ūüôā . In your viewDidLoad event handler, add the below line of code:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(check) name:UIApplicationDidBecomeActiveNotification object:nil];

.. and add a method by the name “check” as mentioned in the quote above.

Screen Shot 2015-12-19 at 5.11.46 PM.png

THAT’S ALL FOR YOU TO IMPLEMENT 3D TOUCH USING OBJECTIVE C

-Cheers!!

Rohant K.


		

Could not find developer disk image

Hello There!

You’ll find this message in your Xcode IDE, if you have recently updated your iOS Device (iPhone or iPad) with latest OS and trying to debug the your iOS app with your updated iOS device.

images.png

We’ll if you have done so, you need to also update your Xcode IDE version to the latest one from your App Store. There should be an update for this available for sure from Apple.

After you have updated the Xcode IDE, this message should go off.

-Cheers!!