小编Sul*_*eed的帖子

第一次启动应用程序时调用didReceiveRemoteNotification

我已经实现了didReceiveRemoteNotification方法.它工作并显示一个视图控制器,其中包含通过的通知数据.这仅适用于应用程序已在前台或后台运行的情况.但是,当应用程序未运行且用户单击通知时,应用程序将启动,但看起来好像没有收到任何通知.通知未写入文本文件,并且未按下viewcontroller.

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive)
    {
        NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];

        NSString *alertMsg = @"";
        NSString *badge = @"";
        NSString *sound = @"";
        NSString *custom = @"";

        if( [apsInfo objectForKey:@"alert"] != NULL)
        {
            alertMsg = [apsInfo objectForKey:@"alert"];
        }


        if( [apsInfo objectForKey:@"badge"] != NULL)
        {
            badge = [apsInfo objectForKey:@"badge"];
        }


        if( [apsInfo objectForKey:@"sound"] != NULL)
        {
            sound = [apsInfo objectForKey:@"sound"];
        }

        if( [userInfo objectForKey:@"Type"] != NULL)
        {
            custom = [userInfo objectForKey:@"Type"];
        }

        // Set …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c push-notification apple-push-notifications ios

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

如何从Objective C中的另一个类正确访问变量

我看过各种论坛试图找到解决这个问题的方法.我目前有2个类,BluetoothViewController和AccountViewController.我想要做的是将用户从AccountViewController中选择的帐户传递给BluetoothViewController,这样我以后可以在BluetoothViewController中使用该字符串.我所做的是在BluetoothViewController.h中创建一个AccountViewController实例,并在AccountViewController.h文件中为该字符串创建了一个属性.我要访问的字符串是"account8"

我的AccountViewController.h文件:

@interface AccountViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{

    NSArray     *tableData;
    int         cellValue;
    NSString    *cellContents;
    NSString    *account8;

}

@property (nonatomic, retain) NSArray   *tableData;
@property (nonatomic, retain) NSString  *cellContents;
@property (nonatomic, retain) NSString  *account8;
Run Code Online (Sandbox Code Playgroud)

我的AccountViewController.m文件:

#import "AccountViewController.h"


@interface AccountViewController ()

@end

// Implementing the methods of ViewController
@implementation AccountViewController

@synthesize tableData;
@synthesize cellContents;
@synthesize account8;


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
    account8 = [tableData objectAtIndex:indexPath.row];

    BluetoothViewController *bluetoothViewController = [[BluetoothViewController alloc] initWithNibName:@"BluetoothViewController" bundle:nil];
    [kAppDelegate setSelectedTabWithTag:-1];
    [self.navigationController pushViewController:bluetoothViewController animated:YES];

}
Run Code Online (Sandbox Code Playgroud)

我的BluetoothViewController.h

#import "AccountViewController.h" …
Run Code Online (Sandbox Code Playgroud)

xcode class object objective-c ios

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

UIView没有从XIB文件Swift调整大小

我创建了一个带有UIView的xib文件。我正在情节提要中使用此视图,并希望根据其中的内容调整大小。当我在情节提要中明确设置视图的高度时,它与XIB文件的高度相同。每个电话屏幕似乎也具有相同的xib高度和宽度,这导致视图从屏幕上移开,无论我在情节提要中设置了什么约束。

我已经尝试过这样做以隐藏视图,并将横幅的高度设置为35

self.specialistBanner.pillView.isHidden = true  
specialistBannerHeight.constant = 35
Run Code Online (Sandbox Code Playgroud)

我试过了

specialistBannerHeight.constant = 35
Run Code Online (Sandbox Code Playgroud)

使故事板中的视图变小

我也尝试过

self.specialistBanner.sizeToFit()
Run Code Online (Sandbox Code Playgroud)

无济于事

XIB文件用于专家横幅视图 XIB文件用于专家横幅视图

xib文件中的标签 xib文件中的标签

胫骨内的药丸视图 胫骨内的药丸视图

使用视图控制器内部的xib视图的情节提要文件 使用视图控制器内部的xib视图的情节提要文件

class SpecialistBannerView: UIView {

@IBOutlet weak var bannerTitle: UILabel!
@IBOutlet weak var pillView: PillCollectionView!

var viewModel = SpecialistBannerViewModel()

// Initialize xib
let SpecialistBannerView = "SpecialistBannerView"

override func awakeFromNib() {
    super.awakeFromNib()
    self.translatesAutoresizingMaskIntoConstraints = false
}

override init(frame: CGRect) {
    super.init(frame: frame)
    initXib(view: self)
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    initXib(view: self)
}

func initXib(view: SpecialistBannerView) {

    let viewToShow = …
Run Code Online (Sandbox Code Playgroud)

xcode storyboard xib uiview swift

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

UIAlertView无法正常运行

当我尝试解雇我的UIAlertView时遇到问题.UIAlertView正确启动,并显示两个按钮:"是"和"否".但是,当我选择是按钮时,没有任何反应.我想知道我做错了什么,以及选择是按钮时为什么没有出现.

我的代码如下:

-(IBAction)gotoURL
{

    [self displaySafariDialogue];

}

-(void)displaySafariDialogue
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Are you sure you wish to exit this app and launch the safari browser?"
                                                    message:@"Click yes to continue"
                                                   delegate:nil
                                          cancelButtonTitle:@"Yes"
                                          otherButtonTitles:@"No", nil];
    [alert setTag:100];
    [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    NSLog(@"Alert view button clicked");

    if(alertView.tag == 100)
    {

        if (buttonIndex==0)
        {
            NSLog(@"Yes button selected");
            NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

            if (![[UIApplication sharedApplication] openURL:url])
                NSLog(@"%@%@",@"Failed to open url:",[url description]);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

xcode objective-c uialertview ios

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