In doc
To add a pass to the library:
Create an instance of the PKPass class for the pass, initializing it with the pass’s data.
Use the containsPass: method of the PKPassLibrary class to check whether the pass is in the library. Your app can use this method to detect the presence of a pass, even if it doesn’t have the entitlements to read passes in the library.
If the pass isn’t in the library, use an instance of the PKAddPassesViewController class to let the user add it.
Present the add passes view controller modally, with animation.
Is there any way to add a pass to my passbook without initializing PKAddPassesViewController?
Document clearly says, The PKPass class represents a single pass.
Also, there is no such method in PKClass to add it in the library.
So, you need to use PKAddPassesViewController that lets your app show a pass and prompt the user to add that pass to the pass library.
Related
In one of my view controllers, I have a lot of possible subviews that can be created based on the status of the data received. I am trying to make them class variables so they can be accessible throughout the file and am using lazy so that I don't create views I don't need. However, I need to make sure the views that could be displayed get removed if the status changes and would want to call .removeFromSuperview(). But I know that lazy variables get initialized the first time they get referenced and that would defeat the purpose of trying to save memory.
Yes, if you referenced the lazy variable in order to call removeFromSuperview, it would first create the view and then call removeFromSuperview on it. You should likely design another way, without lazy. I would recommend starting with the simplest approach (such as Optional properties, checking if it's nil, and creating it if necessary), and then extracting duplicated code. lazy solves one very specific problem in a very limited way. If you don't need precisely what it offers, you generally will need to build something custom
I'm making a music app, which has a lot of variables flying around as songs are chosen, based on artists & albums and all sorts of things.
I'm trying to make my app a bit easier to use by sending all of those variables out to a new class, which I consider as kind of like a 'helper cell' in excel.. It stores a bunch of data so I don't have to keep passing and receiving extras.
The idea is this:
The user chooses a song, and the artist/album/song information is passed out to the helper class.
Next, a music service starts, taking the chosen songs path from the helper class, and playing it.
At the same time, an activity starts, displaying the chosen artist/album/song, again, from the helper class. Next/previous buttons are included here, and once clicked, the helper class' current song is changed, and the music service is instructed to receive the variables from the helper class again.
What type of class would this be? What would it extent, how can I instantiate it, and how can I send and receive variables to/from that class?
Use an Application instance to hold application-level variables.
Extend android.app.application
Define your application in the AndroidManifest.xml
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:name=".MainApplication">
To get your application instance in your activities, call getApplication()
For example, in your onCreate() method of your activity, you would use this code, assuming you named your application class "MainApplication":
Application application = ((MainApplication)getApplication());
Album album = application.getAlbum();
Song song = application.getSong();
...
Depending on what the exact implementation you are trying to do, you could also use SharedPreferences to store these variables and change them as needed it when a new song is selected, etc. http://developer.android.com/guide/topics/data/data-storage.html#pref
I am trying to make a crossword app for IOS but i Don't know that how to check if a string is valid english word or not.
How can i check it.
Is there any API or online facility to check it.
Thanks in Advance
Easy to do in iOS5 using the UIReferenceLibraryViewController class' +dictionaryHasDefinitionForTerm: method.
A UIReferenceLibraryViewController object provides a dictionary
service to look up the definition of terms. You create and initialize
a reference library view controller using the initWithTerm: method.
You pass the term to define as the parameter to this method and the
definition is displayed. You can present this view controller modally
or as part of another interface. On iPad, you can set the reference
library view controller as the content view controller of a
UIPopoverController object. Optionally, use the
dictionaryHasDefinitionForTerm: class method to check if a definition
is available for a given term before creating an instance—for example,
use this method if you want to change the user interface depending on
whether a definition is available.
There is no API for this.
In order to do this, you will need to have a dictionary file (text file or database) in your application bundle. One of the faster ways to check will be to load the dictionary into memory when the application launches so you don't have to read the file for each word. This may be overkill if you simply want hardcoded crosswords, but if you are randomly generating them then this is a must.
I am new in iphone development and i needed a array which i use to access in different class so my senior told me that you should declare in App delegate and access it another class in which it require, so i wrote line for that
MyAppAppDelegate * appObject =
(MyAppAppDelegate*)[[UIApplication sharedApplication]delegate];
I done my task successfully but i couldn't get it 100%. Someone tell that why we use this and in what exactly situation in which we've to use this?
AppDelegate is loaded first when you run your application as it contains window. So, the variable and objects you want to access throughout your project is declared in AppDelegate. You just have to create an instance and you can access all the objects in AppDelegate.
ApplicationDelegate can be useful as a singleton class but you have to use it with discretion - and there are varying opinions on this - but if you have a few global type properties or methods you want to recall from various other classes, and I emphasize few, then ApplicationDelegate may be a nice place to add these.
And yes, it is bad design - but you can get away with it if you are prudent and as #Sedate Alien mentions, take a look at dependency injection.
The purpose of ApplicationDelegate, by the way, is mainly to handle events like loading your application, when you return to home screen, when you come back from home screen, etc.
I'm new to Objective-C so I may be doing this completely wrong, and if I am please correct me. I am trying to make a separate class in my iPhone app just for skinning buttons. My hope is that this will allow me to reuse as much code as possible but before I spend too much time on it, I would like to know if its possible/a good idea to send a message to a UI Control from another class, and if i can, how should I do it? right now im trying to pass the sender ID to my SkinTools class and message that but it doesn't look like it will allow me to message the layer object.
So, am I just completely off the wall here, or is this possible?
Consider looking into using the delegate pattern.
One could just use the addTarget:selector: method for this purpose. As target set the class you want to send the message to, as selector the method you want to call on the class.
You could add some iVars to your class, like id buttonTarget and SEL buttonSelector and create an initializer like -initButtonWithTarget:selector: to set these values on initialization.
It turns out categories was the answer I needed, then I can just add a skin method to each control I use. I can even put them all in the same file to make it easy to get to.