小编Had*_*adu的帖子

如何将ABRecordRef添加到iPhone中的NSMutableArray?

我想创建一个ABRecordRef(s)数组来存储具有有效生日字段的联系人.

   NSMutableArray* bContacts = [[NSMutableArray alloc] init];
   ABAddressBookRef addressBook = ABAddressBookCreate();
   CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
   CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

   for( int i = 0 ; i < nPeople ; i++ )
   {
       ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i );
       NSDate* birthdayDate = (NSDate*) ABRecordCopyValue(ref, kABPersonBirthdayProperty);
       if (birthdayDate != nil){
           [bContacts addObject:ref];
       }
   }
Run Code Online (Sandbox Code Playgroud)

编译器显示此警告: 警告:传递'addObject:'的参数1'从指针目标类型中丢弃限定符 我在Web上搜索并发现我必须将ABRecordRef强制转换为ABRecord*以便能够存储在NSMutableArray中.

[bContacts addObject:(ABRecord*) ref];
Run Code Online (Sandbox Code Playgroud)

但似乎ABRecord不是iOS框架的一部分.现在我如何将ABRecordRef存储到NSMutableArray?

iphone xcode objective-c nsmutablearray addressbook

10
推荐指数
3
解决办法
7237
查看次数

在本地通知iOS10中播放长音

我在本地通知中播放自定义声音,在iOS 10中,当设备被锁定时,一切正常,声音播放到最后.但是当设备解锁时,只要通知栏隐藏(大约5秒钟),声音就会停止播放.

PS.它在iOS 9中工作正常,只要播放通知声音,通知栏就会保持在顶部.

这是一个错误还是我错过了什么?

编辑:

我已经测试过,UNUserNotificationCenter并且已弃用UILocalNotification.两者都是一样的结果.

nsnotificationcenter ios uilocalnotification ios10

5
推荐指数
0
解决办法
500
查看次数

从地址簿中删除一个组

我在代码中的地址簿中创建了一些组.我使用下面的代码删除特定组.ABAddressBookRemoveRecord()返回YES.但该团体仍在那里!代码有什么问题?

BOOL res;
CFErrorRef error;
ABAddressBookRef ab = ABAddressBookCreate();

NSArray *groups = (NSArray *) ABAddressBookCopyArrayOfAllGroups(ab);

for (id _group in groups)
{
    NSString *currentGroupName = [[NSString alloc] init];
    currentGroupName = (NSString*) ABRecordCopyValue(_group, kABGroupNameProperty);

    if ([groupName isEqualToString:currentGroupName])
    {
        [currentGroupName release];
        res = ABAddressBookRemoveRecord(ab, _group, &error);
        return res;
    }
    [currentGroupName release];
}

return NO;
Run Code Online (Sandbox Code Playgroud)

iphone objective-c addressbook

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

Homebrew Apache在干净安装的Sierra上没有使用奇怪的警告

我试图在干净安装的macOS Sierra上安装带有自制软件的Apache. brew install php71 --with-httpd24

我在安装过程中多次收到此警告

Warning: Use httpd instead of deprecated homebrew/apache/httpd24

使用此日志完成Apache的安装:

Warning: Use httpd instead of deprecated homebrew/apache/httpd24
==> Installing homebrew/php/php71 dependency: homebrew/apache/httpd24
==> Downloading https://homebrew.bintray.com/bottles/httpd-2.4.27_2.sierra.bottl
==> Downloading from https://akamai.bintray.com/19/19bf2114d17e94601fa6eed220a0f
######################################################################## 100.0%
==> Pouring httpd-2.4.27_2.sierra.bottle.tar.gz
==> Caveats
To have launchd start httpd now and restart at login:
  brew services start httpd
Or, if you don't want/need a background service you can just run:
  apachectl start
==> Summary
  /usr/local/Cellar/httpd/2.4.27_2: 1,620 files, 25.9MB
Run Code Online (Sandbox Code Playgroud)

并且用这个日志安装了php71:

==> Installing homebrew/php/php71 --with-httpd24 …
Run Code Online (Sandbox Code Playgroud)

apache homebrew macos-sierra

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

不使用 UITableView 中的可重用单元格和每个单元格中的 CollectionView

我有一个UITableView并且在它的原型单元中有一个UICollectionView.

MainViewController是代表,UITableViewMyTableViewCell班级是代表UICollectionView

在更新每个TableViewCell内容时,我调用cell.reloadData()使单元格内的 collectionView 重新加载其内容。

当我使用可重用单元格时,当每个单元格出现时,最后一个单元格的内容消失了!。然后它从 URL 加载正确的内容。

UITableViewCells最多有 5 到 10 个。所以我决定不将可重复使用的单元用于UITableView. 我将 tableView 方法中的单元格创建行更改为:

let cell = MyTableViewCell(style: .default, reuseIdentifier:nil)
Run Code Online (Sandbox Code Playgroud)

然后我在 MyTableViewCell 类(它是 UICollectionView 的委托)中得到一个错误,在这个函数中:

override func layoutSubviews() {
    myCollectionView.dataSource = self
}

EXC_BAD_INSTRUCTION CODE(code=EXC_I386_INVOP, subcode=0x0)
fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)

MyTableViewCell.swift

import UIKit
import Kingfisher
import Alamofire

class MyTableViewCell: UITableViewCell, UICollectionViewDataSource {


    struct …
Run Code Online (Sandbox Code Playgroud)

uitableview reuseidentifier ios uicollectionview swift

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

使用 Eloquent whereNotIn 时查询非常慢

我有一个Question来自非常大的问题表(600,000 条记录)的模型,与CustomerAnswerProduct模型相关。关系与这个问题无关,但我提到它们是为了澄清我需要使用 Eloquent。当我打电话时,Question::with('customer')->get();它运行平稳且快速。

但是还有另一个表,其中我列出了question_id不应显示的所有问题(出于特定原因)。

我尝试了这段代码:

    // omitted product ids, about 95,000 records
    $question_ids_in_product = DB::table('question_to_product')
                  ->pluck('product_id')->all();
    $questions =  Question::with('customer')
                  ->whereNotIn('product_id', $question_ids_in_product)
                  ->paginate($perPage)->get();
Run Code Online (Sandbox Code Playgroud)

花费了很多时间并显示此错误: SQLSTATE[HY000]: General error: 1390 Prepared statement contains too many placeholders

有时Fatal error: Maximum execution time of 30 seconds exceeded

当我使用普通 sql 查询运行它时:

SELECT * FROM questions LEFT JOIN customers USING (customer_id) WHERE question_id NOT IN (SELECT question_id FROM question_to_product)

只需要80毫秒

在这种情况下我该如何使用 Eloquent?

mysql laravel eloquent

0
推荐指数
1
解决办法
1132
查看次数

pluck('id')将字符串值转换为零

我有一个表的主键string类型存储uuid值.当我查询数据时一切都很好.但是当我pluck('id')用来获取所有id的数组时,我得到了一些零!我试着测试它,pluck('firstName')它返回名字数组.当我替换'firstName''id'I时,得到零值数组.

pluck会自动将id值转换为int?这有解决方法吗?

我使用Laravel 5.5

$p = \App\Profile::all()->take(5)
=> Illuminate\Database\Eloquent\Collection {#1015
     all: [
       App\Profile {#980
         id: "client.121138f1-e999-35a1-a16",
         phone: "496.533.3798",
         firstName: "Gabriella",
         lastName: "Steuber",
         company: "",
         email: "tyra.raynor@example.com",
         city_id: 1,
         address: """
           353 Nolan Stravenue\n
           Gudrunshire, MN 36601-6307
           """,
         isCompany: 0,
         status: 1,
         state: "active",
         role: "client",
         created_at: "2017-11-05 11:59:49",
         updated_at: "2017-11-05 11:59:49",
         deleted_at: null,
       },
       App\Profile {#1004
         id: "client.1eac4f8c-e020-31df-96c",
         phone: "290.757.1167 x",
         firstName: "Yadira",
         lastName: "Dietrich",
         company: …
Run Code Online (Sandbox Code Playgroud)

laravel eloquent laravel-5 laravel-5.5

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