小编Han*_*him的帖子

UIActivityViewController在iOS-11中复制url

当用户仅从iOS 11中的活动控制器中选择"复制"时,该URL将重复.它在iOS 10上正常运行

使用以下代码

@IBAction func shareButtonPressed() {
    guard let url = URL(string: "http://google.com") else { return }
    let shareText = "Share Text!"
    let items: [Any] = [shareText, url]
    let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
    present(activityViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

将共享文本提供为:

Share Text! 
http://google.comhttp://google.com
Run Code Online (Sandbox Code Playgroud)

uiactivityviewcontroller swift ios11

8
推荐指数
1
解决办法
809
查看次数

iOS 7中使用iCloud通知的核心数据

我已经为我的应用添加了iCloud支持.当用户更新他的数据时,我收到了通知NSPersistentStoreDidImportUbiquitousContentChangesNotification

那很棒

但是,我有这些问题

  1. 我找不到will这个通知的版本,我可以用它来显示加载器,例如数据库将被更新
  2. 由于我找不到will版本,所以我使用相同的通知来显示加载器,告诉用户数据库正在更新...此通知中的问题是,如果内容发生更改,可以多次调用它iCloud相对较大,导致我显示几个加载指示器!
  3. 有没有办法可以手动触发iCloud更新?

.


我通过这样做添加了对Core数据的iCloud支持:

在NSManagedObjectContext中

_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
_managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy;
Run Code Online (Sandbox Code Playgroud)

在NSPersistentStoreCoordinator中

[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{NSPersistentStoreUbiquitousContentNameKey:@"iCloudStore"} error:nil];
Run Code Online (Sandbox Code Playgroud)

并在NSPersistentStoreDidImportUbiquitousContentChangesNotification通知方法

- (void)persistentStoreDidImportUbiquitousContentChanges:(NSNotification *)notification
{
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
    [managedObjectContext performBlock:^{
        [managedObjectContext mergeChangesFromContextDidSaveNotification:notification];

        dispatch_async(dispatch_get_main_queue(), ^{
            UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
            MBProgressHUD *hud = [MBProgressHUD HUDForView:mainWindow];
            if (hud == nil) {
                hud = [[MBProgressHUD alloc] initWithWindow:mainWindow];
            }
            [mainWindow addSubview:hud];
            hud.labelText = NSLocalizedString(@"Progress updated", nil);
            [hud show:YES];
            [hud hide:YES …
Run Code Online (Sandbox Code Playgroud)

core-data objective-c icloud ios7

6
推荐指数
1
解决办法
1484
查看次数

从Swift中的AppDelegate中解开UIWindow两次

要获取Objective-c中的rootViewController,您可以使用下面的代码行

[[[UIApplication sharedApplication] delegate] window].rootViewController
Run Code Online (Sandbox Code Playgroud)

我试图在swift中做同样的事情

UIApplication.sharedApplication().delegate?.window?.rootViewController
Run Code Online (Sandbox Code Playgroud)

但我得到了这个错误

"的UIWindow?没有名为'rootViewController'的成员

和建议说,你必须解开一个UIWindow两次UIWindow??

UIApplication.sharedApplication().delegate?.window??.rootViewController
Run Code Online (Sandbox Code Playgroud)

我的问题是:为什么我需要打开窗口两次?

.

.


我查看了API并发现了

protocol UIApplicationDelegate : NSObjectProtocol {
    optional var window: UIWindow? { get set }
}
Run Code Online (Sandbox Code Playgroud)

窗口有一个可选的

class UIWindow : UIView {
    var rootViewController: UIViewController?
}
Run Code Online (Sandbox Code Playgroud)

rootViewController也有一个可选项

.

.


我想可能是因为UIApplicationDelegate协议中的UIWindow已经有了optional,UIWindow?所以我在Playground中尝试了以下内容

@objc protocol MyApplicationDelegate {
    optional var myWindow: MyWindow? { get set }
}

class MyWindow : NSObject {
    var rootViewController: Int?
    init(number: Int) {
        rootViewController = number
    }
}

class …
Run Code Online (Sandbox Code Playgroud)

objective-c uiwindow appdelegate swift

2
推荐指数
1
解决办法
1663
查看次数