应用程序启动时的操作
我希望每次我的应用程序启动时(甚至可能从后台恢复)它都会执行一个操作(例如 TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
)。 我还希望可以通过应用程序设置包中的开关禁用此操作(启动时)。我应该怎么办?感谢您的关注。
ps 如果我使用了不正确的词语,我深表歉意..我是初学者:)
I'd like that each time my app starts up (possibly even when it's restored from background) it makes an action (for example TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
).
I'd also like that this action (on startup) can be disabled by a switch in the setting bundle of the app. What should I do? Thanks for your attention.
p.s. I apologize if I used incorrect words.. I'm a beginner :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在应用程序委托中实现多种方法,这些方法可在
UIApplicationDelegate
协议中使用。当您的应用程序首次启动时,将调用
applicationDidFinishLaunching
。当您的应用程序从后台恢复时,将调用
applicationWillEnterForeground
。添加到设置包中的开关将有一个与其关联的键,该键是一个 NSString 。开关在该键下的标准
NSUserDefaults
中存储编码为NSNumber
的布尔值。您可以从标准用户默认值中读取布尔值,并使用它来确定是否执行该操作。有关如何添加设置包的苹果文档是 此处。
在您的设置包中,您需要一个切换开关。您将在标准用户默认值中查找的密钥由
Key
字段指定。切换开关的默认值由DefaultValue
字段指定。 请参阅此处这是您需要在
applicationDidFinishLaunching
中执行的操作 方法There are several methods which you can implement in your application delegate which are available in the
UIApplicationDelegate
protocol.When your app is first launched
applicationDidFinishLaunching
is called.When your app is restored from the background
applicationWillEnterForeground
is called.A switch which you add to your setting bundle will have a key, which is an
NSString
, associated with it. A switch stores a boolean value encoded as anNSNumber
in the standardNSUserDefaults
under that key. You can read the value of the boolean from the standard user defaults and use it to determine whether to perform the action.Apples documentation on how to add a settings bundle is here.
In your settings bundle you'll need a toggle switch. The key that you will look up in the standard user defaults is specified by the
Key
field. The default value for your toggle switch is specified by theDefaultValue
field. See hereHere is what you need to do in your
applicationDidFinishLaunching
method在 voidDidLoad {} 方法中初始化它。要禁用它,您可以使用对象库中的开关
Initialise it in voidDidLoad {} method. For disabling it you can use switch from object libary
这很简单,我用它来从启动画面到主页进行很酷的过渡。
您需要将代码放入 AppDelegate m 文件中。
用于
在启动时运行代码。
使用以下方法来管理后台<->前景过渡:
希望这对您有帮助。
It's easy and I used it to make a cool transition from the splash screen to the home page.
You need to put your code inside the AppDelegate m file.
use
to run code at startup.
use the following methods to manage the Backgroud <-> Foreground transitions:
Hope this helps you.