我已经实现了一个URL方案,并使用它通过调用方法将数据传递给我的应用程序.整个代码如下所示
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
// Check the calling application Bundle ID
if ([[url scheme] isEqualToString:@"yuvitime"])
{
NSLog(@"URL scheme:%@", [url scheme]);
NSString * yuvitimeRequestValue = [url query];
NSDictionary * userInfor = [[NSDictionary alloc]initWithObjectsAndKeys:yuvitimeRequestValue, @"YuvitimeRequest", nil];
NSNotificationCenter * notificationCentre = [NSNotificationCenter defaultCenter];
[notificationCentre postNotificationName:@"URLSCHEMEACTIVATEDNOTIFICATION" object:self userInfo:userInfor];
return YES;
}
else
return NO;
}
Run Code Online (Sandbox Code Playgroud)
如果我的应用程序在后台,一切正常.单击URL时,应用程序将返回到Foreground,URL将按照上述函数中的编码进行处理.
但是,如果应用程序已终止(应用程序尚未启动),则通过单击URL,它仅启动应用程序而不调用上面显示的处理函数.
经过搜索,我得到的最好结果就是这个
application:WillFinishLaunchingWithOptions:
当要求打开URL时,此方法的返回结果与application:didFinishLaunchingWithOptions:
方法的返回结果相结合,以确定是否应该处理URL.如果任一方法返回NO,则系统不会调用application:openURL:options
:method.如果未实现其中一个方法,则仅考虑已实现方法的返回值.
- application:didFinishLaunchingWithOptions:
此方法表示您处理launchOptions字典中任何键的最后机会.如果您没有评估application:willFinishLaunchingWithOptions:
方法中的键,则应该在此方法中查看它们并提供适当的响应.不是app委托的对象可以通过观察名为的通知UIApplicationDidFinishLaunchingNotification
并访问通知的userInfo字典来访问相同的launchOptions字典值.该方法返回后不久发送该通知.此方法的返回结果与application:willFinishLaunchingWithOptions:
方法的返回结果相结合,以确定是否应处理URL.如果任一方法返回NO,则不处理URL.如果未实现其中一个方法,则仅考虑已实现方法的返回值.
尽管有解释,我仍然不知道该怎么做,我在网上找不到其他任何东西.
谢谢
问候
下面的代码据说可以设置一个线程安全的单例:
class Singleton {
static var shared = Singleton()
private let internalQueue = DispatchQueue(label: "SingletionInternalQueue", qos: .default, attributes: .concurrent)
private var _foo: String = "aaa"
var foo: String {
get {
return internalQueue.sync { _foo }
}
set (newState) {
internalQueue.async(flags: .barrier) { self._foo = newState }
}
}
func setup(string: String) {
foo = string
}
}
Run Code Online (Sandbox Code Playgroud)
但我不明白这个目的.
例如,如果我希望get
价值foo
,我不应该只是阅读它吗?应始终在主线程上执行操作,那么添加另一个线程又有什么意义呢?
与此类似set
:如果我担心同时设置值的多个源,我们不能简化该代码并消除.barrier
参数吗?
internalQueue.async(flags: .barrier) { self._foo = newState}
Run Code Online (Sandbox Code Playgroud)
如果它在一个sync
块中,是不是强制它进入主线程?如果是这样,那为什么代码不需要 …
我希望能够构建一个简单的电子邮件客户端来发送电子邮件.
我查看了使用MessageUI框架构建电子邮件客户端的IOS编程101教程,但我想在我的应用程序中实现的内容略有不同.
我想要实现的是,当我按下按钮时,预先组合的电子邮件(将由我编写,例如,像YOLO一样)将直接发送给收件人.
无论如何我能做到这一点吗?
PS:我根本不需要Mail ComposeViewController,只是一个发送预合成邮件的简单按钮.
非常感谢
问候
email-integration objective-c ios swift mfmailcomposeviewcontroller