小编gog*_*elj的帖子

如何以编程方式访问iOS系统字体

我试图更改导航栏标题的字体大小.我知道我可以使用以下方法设置其属性:

var attributes = [ NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont(name: "the font name", size: 18)! ]
Run Code Online (Sandbox Code Playgroud)

...

 self.navigationController?.navigationBar.titleTextAttributes = attributes
Run Code Online (Sandbox Code Playgroud)

我似乎无法找到正确的'系统'字体名称.

我是在默认的,即System,字体名称之后.我尝试打印所有可用的字体只是为了发现它不属于一个家庭,似乎没有一个明确的名称.

cocoa-touch ios swift

36
推荐指数
4
解决办法
4万
查看次数

应用程序终止时推送通知

如果应用程序在后台和/或应用程序位于前台,我的应用程序可以正常使用推送通知.

我遇到的问题是如果应用程序被终止(我强制双击主页按钮,找到应用程序,然后向上滑动).

我正在使用ios 9和swift 2.

在app delegate中,didFinishLaunchingWithOptions,我这样做:

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)

application.registerUserNotificationSettings(settings)

application.registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)

然后:

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {        
        application.registerForRemoteNotifications()
}
Run Code Online (Sandbox Code Playgroud)

其次是didRegisterForRemoteNotificationsWithDeviceToken&didFailToRegisterForRemoteNotificationsWithError.

然后,我使用相对较新的方法:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {...}
Run Code Online (Sandbox Code Playgroud)

根据文档和这个链接,与旧版本相反,didReceiveRemoteNotification如果应用程序被终止,则会调用此方法(与调用will/doneLaunchingWithOptions相反).

但是,如果有一个推(已收到 - 我可以在屏幕上看到它)并且我终止后启动应用程序,这个方法似乎不会被称为处理推送的代码(只需发布一个通知所以它被相应的ViewController拾取)不会被调用.

我错过了什么?我需要在didFinishLaunchingWithOptions中进行额外的检查吗?别的地方?

push-notification apple-push-notifications ios swift2

5
推荐指数
1
解决办法
1581
查看次数

使用生成器迭代 Mongo 中的大型集合

我有一个包含 500K+ 文档的集合,这些文档存储在单个节点 mongo 上。我的 pymongo cursor.find() 时不时会因为超时而失败。

虽然我可以设置find忽略超时,但我不喜欢这种方法。相反,我尝试了一个生成器(改编自这个答案和这个链接):

def mongo_iterator(self, cursor, limit=1000):
        skip = 0
        while True:
            results = cursor.find({}).sort("signature", 1).skip(skip).limit(limit)

            try:
                results.next()

            except StopIteration:
                break

            for result in results:
                yield result

            skip += limit
Run Code Online (Sandbox Code Playgroud)

然后我使用以下方法调用此方法:

ref_results_iter = self.mongo_iterator(cursor=latest_rents_refs, limit=50000)
for ref in ref_results_iter:
    results_latest1.append(ref)
Run Code Online (Sandbox Code Playgroud)

问题:我的迭代器没有返回相同数量的结果。问题是 next() 使光标前进。所以每次通话我都会失去一个元素......

问题:有没有办法调整这段代码,以便我可以检查下一个是否存在?Pymongo 3x 不提供 hasNext() 并且 'alive' 检查不保证返回 false。

python mongodb pymongo pymongo-3.x

5
推荐指数
1
解决办法
3597
查看次数

Google Play - 将版本从内部轨道推广到生产和 Google 审核

我们计划将一个版本从内部轨道转移到生产。

这个版本会再次经过 Google 审核吗?

另外,如果我们有Managed publishing on - you control when approved updates are published,这是否意味着在production review(如果它必须经过另一个)之后我们需要按推出(发布到存储)?

谢谢。

android google-play-console

5
推荐指数
1
解决办法
1223
查看次数

Swift 2.0,UILabel和setTranslatesAutoresizingMaskIntoConstraints

我升级了我的xcode,现在使用Swift 2.0.我在运行时设置并依赖的所有组件都存在问题

setTranslatesAutoresizingMaskIntoConstraints

似乎该方法不再可用,我不得不注释掉代码.结果,所有定位都搞砸了....(冲击,按钮,标签,图像形状)

知道如何解决这个问题吗?

uibutton uilabel swift2

3
推荐指数
1
解决办法
1818
查看次数

NSDate() - Playground vs. Swift Xcode

我注意到当我在Swift游乐场时,对NSDate()的调用会生成一个具有以下格式的日期:

< date time AM|PM >
Run Code Online (Sandbox Code Playgroud)

但是,在xcode/app中,NSDate()会使用此格式生成日期

< date time UTC >
Run Code Online (Sandbox Code Playgroud)

我不清楚为什么会有这样的差异?如何强制xcode始终生成NSDate < date time AM|PM >

xcode swift swift2

3
推荐指数
2
解决办法
311
查看次数

Swift选项 - 从'x'到'x'的条件转换警告总是成功

我想知道是否有办法if let...NSUserDefaults在关键具有已知值的构造中关闭/避免xcode中的"黄色"警告.

例如:

if let x = NSUserDefaults.standardUserDefaults().integerForKey("myKey") as? Int {...}
Run Code Online (Sandbox Code Playgroud)

因为if let我必须使用as?.但是,由于我使用的是已知值类型(在本例中为整数),as? Int因此实际上是多余的 - 这就是我收到'黄色警告'的原因.

思考?有没有更好的方法来编码这些类型的结构?

nsuserdefaults swift2

3
推荐指数
1
解决办法
4505
查看次数

CoreData 和 NSManagedObject 上下文 - 私有与主要

使用私有上下文触发 CoreData (CRUD) 操作与使用performBlockdispatch_async 后台队列中的主上下文触发此类操作之间有区别吗?

是否只是不应该在后台线程中使用主上下文的情况?

苹果文档的链接在这里

core-data objective-c nsmanagedobjectcontext swift

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