小编sir*_*333的帖子

在App未运行时处理推送通知

当我的应用程序没有运行并收到推送通知时,如果我点击该通知,则启动应用程序 - 但是它不会提示用户设置的警报视图,询问他们是否要查看通知的内容与否.它只是发射,并坐在那里.

该推送通知做的工作完美的应用程序时运行-无论是作为活跃APP或者在后台-但没有正常工作时,该应用程序是不能运行的.

我尝试注销launchOptionsNSDictionary,application: didFinishLaunchingWithOptions:看看它带来了什么负载 - 但它出现了"(null)".所以它基本上什么都没有 - 这是没有意义的,因为它不应该包含Notification的负载?

任何人都有任何想法如何在应用程序未运行时如何使Push Notifications工作?

编辑:这是我正在使用的代码,application: didReceiveRemoteNotification只是为了看看是什么:

if (UIApplicationStateBackground) {

    NSLog(@"===========================");
    NSLog(@"App was in BACKGROUND...");
}
else if (UIApplicationStateActive == TRUE) {
    NSLog(@"===========================");
    NSLog(@"App was ACTIVE");
}
else {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 99]; 
    UIAlertView *BOOM = [[UIAlertView alloc] initWithTitle:@"BOOM"
                                                   message:@"app was INACTIVE"
                                                  delegate:self
                                         cancelButtonTitle:@"a-ha!"
                                         otherButtonTitles:nil];
    [BOOM show];
    NSLog(@"App was NOT ACTIVE");
}
Run Code Online (Sandbox Code Playgroud)

所以这应该照顾所有应用程序的状态 - 但事实并非如此.推送通知仅在应用程序运行时有效 - 无论是在后台还是在前台......

================================================

更新/编辑#2:根据"@dianz"建议(下面),我修改了我的代码 …

iphone push-notification apple-push-notifications

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

Swift子类 - 如何覆盖Init()

我有以下类,使用init方法:

class user {
  var name:String
  var address:String

  init(nm: String, ad: String) {
    name = nm
    address = ad
  }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试子类化这个类,但我不断收到错误super.init():

class registeredUser : user {
     var numberPriorVisits: Int

     // This is where things start to go wrong - as soon as I type 'init' it 
     // wants to autocomplete it for me with all of the superclass' arguments, 
     // and I'm not sure if those should go in there or not:
     init(nm: String, ad: String) { …
Run Code Online (Sandbox Code Playgroud)

initialization subclass superclass swift

41
推荐指数
2
解决办法
7万
查看次数

如何在Swift中找出字母是字母数字还是数字

我想计算以下字符串中的字母,数字和特殊字符的数量:

let phrase = "The final score was 32-31!"
Run Code Online (Sandbox Code Playgroud)

我试过了:

for tempChar in phrase {
    if (tempChar >= "a" && tempChar <= "z") {
       letterCounter++
    }
// etc.
Run Code Online (Sandbox Code Playgroud)

但我收到了错误.我尝试了各种其他变体 - 仍然出现错误 - 例如:

无法找到接受提供的参数的'<='的重载

comparison character digits swift

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

如何在Swift中使用println来格式化数字

在Objective-C中注销一个浮点数时,您可以执行以下操作将输出限制为仅两位小数:

float avgTemp = 66.844322156
NSLog (@"average temp. = %.2f", avgTemp);
Run Code Online (Sandbox Code Playgroud)

但是你如何在Swift中做到这一点?你怎么逃避printlnSwift中的其他角色?

这是一个常规的Swift println语句:

println ("Avg. temp = \(avgTemp)")
Run Code Online (Sandbox Code Playgroud)

那么如何限制小数位?

另外,你如何逃避双引号println

nsformatter println swift

22
推荐指数
3
解决办法
5万
查看次数

Swift:如何注销保留对象的数量?

有没有办法快速将对象的保留计数注销到Xcode的控制台?如果没有,那么下一个最佳选择是什么?

iphone reference retain ios swift

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

应用程序在数据库创建尝试时崩溃

我使用"SQLite数据库浏览器"创建了一个sql数据库,将其拖放到我的Xcode项目中,并构建了应用程序.它在模拟器上工作得非常好但在iPhone上崩溃,出现此错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
 reason: 'Failed to create writable database file with message 'The operation could‚ 
not be completed. (Cocoa error 260.)'.'   
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Creates a writable copy of the bundled default database in the application Documents directory:
    NSLog(@"AppDelegate...Looking for embedded Database file...");
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    // Grab the path to the Documents folder:
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = …
Run Code Online (Sandbox Code Playgroud)

database sqlite iphone

11
推荐指数
1
解决办法
3409
查看次数

Linea Pro条形码扫描仪iPhone问题

我下载了iOS SDK从他们的网站凌特Pro设备,并已成功实施了一些在我的应用程序-但我注意到该设备从未似乎工作,而其通过USB电缆连接到Mac.我已经100%验证了这一点,因为只要我从USB线上断开LineaPro底座并运行他们的应用程序,它就会找到扫描仪并且可以工作.否则,没什么.

这当然使得调试几乎不可能,因为如果你没有连接到Xcode,你显然看不到App在Xcode的控制台中可能有任何输出.你不能NSLog任何东西到控制台,你不能放断点,你不能单步执行代码 - 你几乎不能做你开发应用程序时通常做的任何事情.

我实际上不得不求助于创建UITextViews并在运行时向我们输出所有内容(这当然会使界面大大混乱)但即便如此,如果应用程序崩溃,你也永远无法看到你的TextViews:你'重新抛出并回到iOS主屏幕,盯着你所有的小图标.

我有一些关于解决方案的其他想法 - 但就是这样:它们都是解决方法.有没有人知道是否有任何方法可以使用Linea Pro,而它仍然连接到Xcode?

iphone barcode barcode-scanner ios linea-pro

9
推荐指数
1
解决办法
2787
查看次数

Swift Array.map闭包问题

我想改进我使用Swift的Array.map函数编写的闭包

我基本上使用一个数组并使用闭包重新映射它的所有元素.

// Here's the array:
var numbersArray = [1, 2, 3, 4, 5]

// Here's the closure - it takes whatever number is passed into it and 
// multiplies it by 2.0
var multiplier = {  (currentNum: Int) -> Double in
    let result = Double(currentNum) * 2.0
    return result
}

// And here's how I'm calling it:
var newArray = numbersArray.map(multiplier)
Run Code Online (Sandbox Code Playgroud)

这完美无缺.

但是如果我想将所有东西乘以2.1呢?还是3.5?还是有价值的?换句话说,如果我想使我乘以的量也是一个变量怎么办?并将它作为第二个参数传递给闭包?

我尝试将它添加到参数列表中,如下所示:

var multiplier = {  (currentNum: Int, factor: Double) -> Double in
    let result …
Run Code Online (Sandbox Code Playgroud)

arrays mapping closures swift

8
推荐指数
2
解决办法
6161
查看次数

UITableView图像导致崩溃

我已经完成了一百万个UITables - 有字幕,图像,背景,颜色,文字样式 - 你可以说出来.突然间,我正在撞到这张桌子上,特别是在要求拍摄细胞图像的线上.这是代码:

// Configure the cell:
cell.textLabel.font = [UIFont fontWithName:@"Franklin Gothic Book" size:18];
cell.textLabel.text = [leadershipMenu objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [leadershipSubtitlesMenu objectAtIndex:indexPath.row];

// And here's the statement that causes the crash:
cell.imageView.image = [leadershipPhotosMenu objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)

现在,我得到的错误是这样的:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0xcacbc'
Run Code Online (Sandbox Code Playgroud)

我确定导致崩溃的声明是

cell.imageView.image = ...
Run Code Online (Sandbox Code Playgroud)

因为我一评论它一切正常.

我一生都没见过

-[__NSCFConstantString _isResizable]: 
Run Code Online (Sandbox Code Playgroud)

错误.我用谷歌搜索了它,但发现它很少.

非常特别.

有人在那里有任何线索吗?

iphone uitableview uiimageview uiimage

7
推荐指数
1
解决办法
3732
查看次数

弄清楚在UIActivityViewController中点击了哪个图标

使用"社交"框架,在呈现显示所有常用社交媒体图标的模式UIActivityViewController时,有没有办法找出用户点击的确切图标?意思是,如果他们选择Twitter,Facebook,Mail,Message等?

我期待在Docs中可能会看到这个类的一些委托方法,但我什么都看不到.

有人有任何想法吗?

objective-c ios uiactivityviewcontroller

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