私は、ObjectOS-CでビルドされたwatchOS拡張機能を持つiOSアプリケーションを持っています。ロードする(viewDidLoad
)または表示されるとき(viewDidAppear:(BOOL)animated
)、アプリは配列を送信する必要があります。アプリケーションが読み込まれても何も起こりませんが、何らかの形でファイルをアプリケーションに追加すると(内蔵の加算器を使用するか、デスクトップまたはAirDropからファイルを読み込むことによって)、時計アプリケーションが更新されます。リフレッシュボタンを押しても、アプリは動作しません。しかし、いったんファイルを追加すると、それは正常に更新され、完全に更新され始めます。なぜこのようなことが起こるのか分かりませんが、ここで私が使ったコードがあります。私はあまり有用でないコードをいくつか削除しました。 viewDidLoad
でアップルに送信しない情報viewDidLoadで見る
:
-(void)connectToWatch
で
- (void)viewDidLoad
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *appFolderPath = [path objectAtIndex:0];
NSString *inboxAppFolderPath = [appFolderPath stringByAppendingString:@"/Inbox"]; //changes the directory address to make it for the inbox
//move all files from inbox to documents root
//get to inbox directory
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSArray *inboxContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSString stringWithFormat:inboxAppFolderPath,documentsDirectory] error:nil];
//move all the files over
for (int i = 0; i != [inboxContents count]; i++)
{
NSString *oldPath = [NSString stringWithFormat:@"%@/%@", inboxAppFolderPath, [inboxContents objectAtIndex:i]];
//NSLog(oldPath);
NSString *newPath = [NSString stringWithFormat:@"%@/%@", appFolderPath, [inboxContents objectAtIndex:i]];
//NSLog(newPath);
NSError* error;
[[NSFileManager defaultManager] moveItemAtPath:oldPath toPath:newPath error:&error];
NSLog(@"error: %@", error.localizedDescription);
}
//end of moving all files
//Turn every file inside the directory into an array
//add directory in case it doesn't already exist
if (![[NSFileManager defaultManager] fileExistsAtPath: inboxAppFolderPath])
{
[[NSFileManager defaultManager] createDirectoryAtPath: inboxAppFolderPath withIntermediateDirectories:NO attributes:nil error:nil];
NSLog(@"directory created");
}
//a bunch of NSPredicates go here to filter out the array
[self sendStuffToWatch];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self connectToWatch];
}
、-(void)viewDidAppear:(BOOL)animated
で-(void)sendStuffToWatch
-(void)sendStuffToWatch
{
if(self.watchSession)
{
NSError *error;
NSDictionary *applicationDict = @{@"array":recipes};
[self.watchSession updateApplicationContext:applicationDict error:&error];
NSLog(@"sent info to watch");
}
}
で
-(void)connectToWatch
{
//set up WatchConnectivity session
if([WCSession isSupported])
{
self.watchSession = [WCSession defaultSession];
self.watchSession.delegate = self;
[self.watchSession activateSession];
if([WCSession defaultSession].paired){
NSLog(@"Watch session active");
}
else
{
NSLog(@"WATCH NOT CONNECTED");
}
}
}
があり、これだけ
があります-(void)viewDidAppear:(BOOL)animated
{
[self sendStuffToWatch];
}
更新ボタンのコードは
-(IBAction)Refresh:(id)sender
{
[recipeTable reloadData];
[self sendStuffToWatch];
[self viewDidLoad];
}
また、 'view'を強制的にロードし、' viewDidLoad'を呼び出す場合は、 'loadViewIfNeeded'を呼び出すことができます。 – EmilioPelaez
残念ながら、それはうまくいきませんでしたが、すべてをリロードする必要があるリフレッシュボタンの '' viewDidLoad''を呼び出すためには、 '' viewDidLoad''から/ everything /を取って、方法? – JustMe
はい(スーパーを呼び出す以外はすべて)。それがうまくいかない場合は、デバッガを使用してコードを実行し、エラーが発生していないことを確認する必要があります。最初は機能しませんが、ファイルを追加すると機能しますので、最初に実行されたときには何も設定されていません。どの部分が問題を引き起こしているのかを把握しているだけです。 –